HACKERS ELITE
Bienvenido a HACKERS ELITE
porfavor registrate o inicia secion para ver todo el contenido del foro, disfruta tu visita!
Últimos temas
» Me bloquearon mi celular para conectarse a la Red Wifi en Modo Avion
Vie Sep 05, 2014 6:15 pm por JAVIER_77

» Hacker nostale
Vie Jul 20, 2012 5:02 pm por Sweet_Boy

» Chrome OS 20.x pasa al canal estable
Vie Jul 13, 2012 11:15 pm por [D]ement<<<

» Disponible openSUSE 12.2 RC 1
Vie Jul 13, 2012 12:44 am por [D]ement<<<

» NitroShare, comparte archivos y carpetas entre Linux y Windows
Vie Jul 13, 2012 12:26 am por [D]ement<<<

» Linux Mint 13 KDE Release Candidate, disponible
Vie Jul 13, 2012 12:18 am por [D]ement<<<

» LibreOffice 3.5.5, más estabilidad
Vie Jul 13, 2012 12:06 am por [D]ement<<<

» File History, un Time Machine para Windows 8
Miér Jul 11, 2012 9:50 pm por [D]ement<<<

» Como habilitar el logueo automático en Windows
Miér Jul 11, 2012 9:44 pm por [D]ement<<<

» Acronis True Image 2012
Mar Jul 10, 2012 12:15 am por [D]ement<<<

» Virus Informaticos
Mar Mayo 08, 2012 7:10 am por Sokoleonardo

Buscar
 
 

Resultados por:
 


Rechercher Búsqueda avanzada

Septiembre 2017
LunMarMiérJueVieSábDom
    123
45678910
11121314151617
18192021222324
252627282930 

Calendario Calendario


[Tk] Nw Calculating

Ver el tema anterior Ver el tema siguiente Ir abajo

[Tk] Nw Calculating

Mensaje por Sokoleonardo el Sáb Nov 12, 2011 2:31 pm

Echo en Python (Con el modulo Tk Para interfaz grafica)

[Tienes que estar registrado y conectado para ver esa imagen]

Código:

# -*- coding: cp1252 -*-
from Tkinter import *
from random import randrange
from tkMessageBox import showerror
from platform import python_version,system as System
from re import findall
from os.path import exists as Exists
import Tkinter
from os import getcwd
class Calculating:
    def __init__(self):
        self.window = Tk()
        self.window.minsize(244,438)
        self.window.title("Calculating")
        self.window.resizable(0,0)
        self.INnum = "primary"
        self.primary = 0
        #self.secondary = 0
        self.result = 0
        self.behavior = "del"
        self.Operander = ""
        self.mark = Label(self.window,padx=120,pady=210,relief="groove")
        self.mark.place(x=0,y=0)
        self.mark2 = Label(self.window,padx=114,pady=203,relief="groove")
        self.mark2.place(x=6,y=6)
        self.mark3 = Label(self.window,padx=104,pady=10,relief="groove")
        self.mark3.place(x=15,y=53)
        self.mark4 = Label(self.window,padx=104,pady=107,relief="groove")
        self.mark4.place(x=15,y=93)
        self.mark5 = Label(self.window,padx=104,pady=30,relief="groove")
        self.mark5.place(x=15,y=343)
        self.textResultTitle = Label(self.window,text="Result:")
        self.textResultTitle.place(x=25,y=324)
        self.ButtonAdd = Button(self.window,text="Add",command=self.AddResultIfNotChar,state="disable")
        self.ButtonAdd.place(x=195,y=394)
        self.textResultX1 = Label(self.window)
        self.textResultX1.place(x=25,y=345)
        self.textResultOpe = Label(self.window)
        self.textResultOpe.place(x=25,y=360)
        self.textResultX2 = Label(self.window)
        self.textResultX2.place(x=25,y=377)
        self.textResult= Label(self.window)
        self.textResult.place(x=25,y=394)
        self.entryLvL = Entry(self.window,relief="sunken",foreground="green",background="black",insertbackground="blue",selectforeground="red",selectbackground="green",selectborderwidth=2,justify="right",xscrollcommand=self.DelChars)
        self.entryLvL.place(x=15,y=30,width=212)
        self.ButtonFalling = Button(self.window,text="< Del one",fg="orange",command=self.DelOne)
        self.ButtonFalling.place(x=70,y=60)
        self.ButtonDel = Button(self.window,text="Del",fg="red",command=self.DelAll)
        self.ButtonDel.place(x=35,y=60)
        self.Button7 = Button(self.window,text="7",fg="#00FFFF",width=4,height=2,command=self.ADD7)
        self.Button7.place(x=24,y=104)
        self.Button8 = Button(self.window,text="8",fg="#00FFFF",width=4,height=2,command=self.ADD8)
        self.Button8.place(x=64,y=104)
        self.Button9 = Button(self.window,text="9",fg="#00FFFF",width=4,height=2,command=self.ADD9)
        self.Button9.place(x=104,y=104)
        self.Button4 = Button(self.window,text="4",fg="#00FFFF",width=4,height=2,command=self.ADD4)
        self.Button4.place(x=24,y=147)
        self.Button5 = Button(self.window,text="5",fg="#00FFFF",width=4,height=2,command=self.ADD5)
        self.Button5.place(x=64,y=147)
        self.Button6 = Button(self.window,text="6",fg="#00FFFF",width=4,height=2,command=self.ADD6)
        self.Button6.place(x=104,y=147)
        self.Button1 = Button(self.window,text="1",fg="#00FFFF",width=4,height=2,command=self.ADD1)
        self.Button1.place(x=24,y=190)
        self.Button2 = Button(self.window,text="2",fg="#00FFFF",width=4,height=2,command=self.ADD2)
        self.Button2.place(x=64,y=190)
        self.Button3 = Button(self.window,text="3",fg="#00FFFF",width=4,height=2,command=self.ADD3)
        self.Button3.place(x=104,y=190)
        self.Button0 = Button(self.window,text="0",fg="#00FFFF",width=4,height=2,command=self.ADD0)
        self.Button0.place(x=24,y=233)
        self.Button0 = Button(self.window,text="=",fg="#00FFFF",width=4,height=2,command=self.OperateResult)
        self.Button0.place(x=24,y=276)
        self.ButtonOperand1 = Button(self.window,text="+",fg="yellow",width=4,height=2,command=self.Sum)
        self.ButtonOperand1.place(x=144,y=104)
        self.ButtonOperand2 = Button(self.window,text="_",anchor="n",fg="yellow",width=4,height=2,command=self.Subtraction)
        self.ButtonOperand2.place(x=144,y=147)
        self.ButtonOperand3 = Button(self.window,text="*",fg="yellow",width=4,height=2,command=self.Multiplication)
        self.ButtonOperand3.place(x=144,y=190)
        self.ButtonOperand4 = Button(self.window,text="/",fg="yellow",width=4,height=2,command=self.Division)
        self.ButtonOperand4.place(x=144,y=233)
        self.ButtonOperand5 = Button(self.window,text="x^2",fg="yellow",width=4,height=2,command=self.ExponentX2)
        self.ButtonOperand5.place(x=64,y=233)
        self.ButtonOperand6 = Button(self.window,text="x^3",fg="yellow",width=4,height=2,command=self.ExponentX3)
        self.ButtonOperand6.place(x=104,y=233)
        self.ButtonOperand7 = Button(self.window,text="bin",fg="yellow",width=4,height=2,command=self.Bin)
        self.ButtonOperand7.place(x=184,y=104)
        self.ButtonOperand8 = Button(self.window,text="hex",fg="yellow",width=4,height=2,command=self.Hex)
        self.ButtonOperand8.place(x=184,y=147)
        self.ButtonOperand9 = Button(self.window,text="oct",fg="yellow",width=4,height=2,command=self.Oct)
        self.ButtonOperand9.place(x=184,y=190)
        self.ButtonOperand10 = Button(self.window,text="rnd",fg="yellow",width=4,height=2,command=self.Rnd)
        self.ButtonOperand10.place(x=184,y=233)
        self.ButtonOperand11 = Button(self.window,text="And",fg="yellow",width=4,height=2,command=self.And)
        self.ButtonOperand11.place(x=64,y=276)
        self.ButtonOperand12 = Button(self.window,text="Or",fg="yellow",width=4,height=2,command=self.Or)
        self.ButtonOperand12.place(x=104,y=276)
        self.ButtonOperand13 = Button(self.window,text="Xor",fg="yellow",width=4,height=2,command=self.Xor)
        self.ButtonOperand13.place(x=144,y=276)
        self.ButtonOperand14 = Button(self.window,text="Not",fg="yellow",width=4,height=2,command=self.Not)
        self.ButtonOperand14.place(x=184,y=276)
        self.window.tk_setPalette("gray30")
        icon = "icon.ico" if (System() == "Windows") else "icon.png"
        try:
            self.window.iconbitmap(icon)
        except:
            error = 'Not name'+' "'+icon+'" '+ 'in directory: "'+getcwd()+'\\"'  if not Exists("icon.ico") else "File icon.ico is corrupt"
            print error
    def ActualizationWindow(self,num):
        Title = 'Result in "'+self.Operander+'":'
        self.textResultTitle["text"] = Title
        self.textResultX1["text"] = "x1: " + str(num)
        self.textResultOpe["text"] = 'oper: ' +'"' + str(self.Operander) + '"'
        self.textResultX2["text"] = "x2: " + self.entryLvL.get()
        self.textResult["text"] = "= "+str(self.primary)
        self.CompareCharOrNum()

    def ActualizationWindow2(self,resul,ope):
        "= "+str(resul)
        Title = 'Result in "'+ope+'":'
        self.textResultTitle["text"] = Title
        self.textResultX2["text"] = ""
        self.textResultOpe["text"] = "= "+str(resul)
        self.textResultX1["text"] = ope+" ( "+str(self.entryLvL.get())+" ) "
        self.textResult["text"] = ""
        self.CompareCharOrNum()
       
    def Add(self,character):
        self.Delete()
        end = len(self.entryLvL.get())
        self.entryLvL.insert(end, character)

    def Delete(self):
        """Intento de borrar"""
        if self.behavior == "del":
            end = len(self.entryLvL.get())
            self.entryLvL.delete(0,end)
            self.behavior = "none"
               
    def DelAll(self):
        self.primary = 0
        self.behavior = "del"
        self.textResultTitle["text"] = "Result:"
        self.textResultX1["text"] = ""
        self.textResultOpe["text"] = ""
        self.textResultX2["text"] = ""
        self.textResult["text"] = ""
        self.Delete()
        self.CompareCharOrNum()

    def ADD0(self): self.Add("0")
    def ADD1(self): self.Add("1")
    def ADD2(self): self.Add("2")
    def ADD3(self): self.Add("3")
    def ADD4(self): self.Add("4")
    def ADD5(self): self.Add("5")
    def ADD6(self): self.Add("6")
    def ADD7(self): self.Add("7")
    def ADD8(self): self.Add("8")
    def ADD9(self): self.Add("9")

    def DelOne(self):
        Content = self.entryLvL.get()[:-1]
        end = len(Content)
        self.entryLvL.delete(first=end-1)

    def OperateResult(self):
        Num1 = self.primary
        if self.primary and self.entryLvL.get():
            Num = int(self.entryLvL.get())
            if self.Operander == "+":
                self.primary = self.primary + Num
            elif self.Operander == "-":
                self.primary = self.primary - Num
            elif self.Operander == "*":
                self.primary = self.primary * Num
            elif self.Operander == "/":
                self.primary = self.primary / Num
            elif self.Operander == "and":
                self.primary = self.primary & Num
            elif self.Operander == "or":
                self.primary = self.primary | Num
            elif self.Operander == "xor":
                self.primary = self.primary ^ Num
            elif self.Operander == "rnd":
                if self.primary < Num:
                    self.primary = randrange(self.primary,Num+1)
                else:
                    self.primary = randrange(Num,self.primary+1)
        self.ActualizationWindow(Num1)
       
    def Bin(self):
        try:
            x1 = int(float(self.entryLvL.get()))
            result = bin(x1)
            X1 = str(result)
            XX1 = X1 if (len(X1) < 27) else X1[:27]+"_\n"+X1[27:]
            self.ActualizationWindow2(XX1,"bin")
        except NameError:
            showerror("Error Python version!","Use 'bin' in Python version != "+python_version())
        except ValueError:
            pass

    def Hex(self):
        N = self.entryLvL.get()
        if N:
            x1 = long(int(N))
            result = hex(x1)
            X1 = str(result)
            self.ActualizationWindow2(X1,"hex")

    def Oct(self):
        N = self.entryLvL.get()
        if N:
            x1 = long(int(N))
            result = oct(x1)
            X1 = str(result)
            self.ActualizationWindow2(X1,"oct")

    def Not(self):
        N = self.entryLvL.get()
        if N:
            X1 = str(~long(int(N)))
            self.ActualizationWindow2(X1,"Not")

    def ExponentX2(self):
        N = self.entryLvL.get()
        if N:
            X1 = str(int(N) ** 2)
            self.ActualizationWindow2(X1,"x^2")
           
    def ExponentX3(self):
        N = self.entryLvL.get()
        if N:
            X1 = str(int(N) ** 3)
            XX1 = X1 if (len(X1) < 27) else X1[:27]+"_\n"+X1[27:]
            self.ActualizationWindow2(XX1,"x^3")
           
    def Sum(self):
        content = self.entryLvL.get()
        if content:
            self.behavior = "del"
            self.Operander = "+"
            self.primary = float(content)
    def Subtraction(self):
        content = self.entryLvL.get()
        if content:
            self.behavior = "del"
            self.Operander = "-"
            self.primary = float(content)
    def Multiplication(self):
        content = self.entryLvL.get()
        if content:
            self.behavior = "del"
            self.Operander = "*"
            self.primary = float(content)
    def Division(self):
        content = self.entryLvL.get()
        if content:
            self.behavior = "del"
            self.Operander = "/"
            self.primary = float(content)
    def And(self):
        content = self.entryLvL.get()
        if content:
            self.behavior = "del"
            self.Operander = "and"
            self.primary = int(content)
    def Or(self):
        content = self.entryLvL.get()
        if content:
            self.behavior = "del"
            self.Operander = "or"
            self.primary = int(content)
    def Xor(self):
        content = self.entryLvL.get()
        if content:
            self.behavior = "del"
            self.Operander = "xor"
            self.primary = int(content)
    def Rnd(self):
        content = self.entryLvL.get()
        if content:
            self.behavior = "del"
            self.Operander = "rnd"
            self.primary = int(content)

    def AddResultIfNotChar(self):
        if str(self.primary)[0] != 0 and findall("[^0-9]+",str(self.primary)): pass
        self.behavior = "del"
        self.Delete()
        self.entryLvL.insert(0,str(self.primary))
    def CompareCharOrNum(self):
        self.ButtonAdd["state"] = "normal" if (str(self.primary)[0] != "0" and findall("[0-9]+.?",str(self.primary)) and (self.primary <= 999999999999)) else "disable"
       
    def DelChars(self,*delet):
        suspicion = self.entryLvL.get()
        if self.behavior == "del" and suspicion:
            self.Delete()
            Num = suspicion[-1]
            self.entryLvL.insert(0,Num)
        end = len(suspicion)
        self.entryLvL.icursor(end)
        if (end > 21) or (findall("[^0-9.]+",suspicion)) or (suspicion.count(".") > 1):
            self.entryLvL.delete(first=end-1)

machine = Calculating()
machine.window.mainloop()
[/quote]
avatar
Sokoleonardo
Moderador de Seccion
Moderador de Seccion

Mensajes : 52
Nivel : 138
Reputación : 4
Fecha de inscripción : 04/08/2011
Vive en Vive en : Argentina

Volver arriba Ir abajo

Ver el tema anterior Ver el tema siguiente Volver arriba


 
Permisos de este foro:
No puedes responder a temas en este foro.