Skip to content

Instantly share code, notes, and snippets.

@HiroNakamura
Created March 25, 2012 21:39
Show Gist options
  • Save HiroNakamura/2200020 to your computer and use it in GitHub Desktop.
Save HiroNakamura/2200020 to your computer and use it in GitHub Desktop.
Factorial en Tkinter Python
from Tkinter import*
import sys
from math import*
def Factorial(n):
if n==0:
return 1
else:
return n*Factorial(n-1)
def Obtener_Fact():
print "El factorial del número : ",numero.get()," es ",Factorial(numero.get())
res=Factorial(numero.get())
lblt=Label(Formulario1,text="Resultado: "+str(res))
lblt.grid(row=3,column=0)
#------------------------------------------------------------------------------------------
Formulario1=Tk()
Formulario1.title('[Factorial]')
Formulario1.resizable(width=TRUE,height=TRUE)
#------------------------------------------------------------------------------------------
Etiqueta=Label(Formulario1,text="Factorial del número")
numero=IntVar()
txtnumero=Entry(Formulario1,textvariable=numero,width=15)
BotonCalcula=Button(Formulario1,text="Calcular",command=Obtener_Fact,width=10)
txtnumero.grid()
Etiqueta.grid()
BotonCalcula.grid(row=0,column=1)
#------------------------------------------------------------------------------------------
Formulario1.mainloop()
#------------------------------------------------------------------------------------------
@HiroNakamura
Copy link
Author

Otro ejemplo de Tkinter

from Tkinter import *

class Application(Frame):
def say_hi(self):
print "hola a todo mundo"

def createWidgets(self):
    self.QUIT = Button(self)
    self.QUIT["text"] = "QUITAR"
    self.QUIT["fg"]   = "red"
    self.QUIT["command"] =  self.quit

    self.QUIT.pack({"side": "left"})

    self.hi_there = Button(self)
    self.hi_there["text"] = "Saludar",
    self.hi_there["command"] = self.say_hi

    self.hi_there.pack({"side": "left"})

def __init__(self, master=None):
    Frame.__init__(self, master)
    self.pack()
    self.createWidgets()

root = Tk()
app = Application(master=root)
root.title('Ejemplo de GUI Tkinter')
app.mainloop()
root.destroy()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment