1
2
3
4 """
5 Manejo de la librería gráfica Tk...
6 Autor: Rodrigo A. Carreño V. (rocarreno)
7 """
8
9 from Tkinter import *
10 import tkSimpleDialog
11 import tkMessageBox
12
13
14
15
16 def nuevo():
17 print 'Llamo Nuevo'
18 a=tkSimpleDialog.askstring('Digite cadena:','Juan Pablo')
19 print 'Almaceno la cadena: ',a
20
21 def abrir():
22 print "Llamo Abrir!"
23 b=int(tkSimpleDialog.askstring('Digite enteros:',''))
24 print 'Almaceno el entero: ',b
25
26 def guardar():
27 print "Llamo Guardar!"
28 c=float(tkSimpleDialog.askstring('Digite reales:',''))
29 print 'Almaceno el real: ',c
30
31 def boton1():
32 print "Oprimio el boton1!"
33 tkMessageBox.showwarning("Precaucion","Usted Opromio el boton 1")
34
35 def boton2():
36 print "Oprimio el boton2!"
37 tkMessageBox.showinfo("Informacion","Usted Oprimio el boton 2" )
38
39 def boton3():
40 print "Oprimio el boton3!"
41 tkMessageBox.showerror("Error","Usted Oprimio el boton 3" )
42
43 def boton4():
44 print "Oprimio el boton4!"
45 top = Toplevel()
46
47 root = Tk()
48
49
50 root.minsize(300,200)
51
52
53 toolbar = Frame(root)
54
55
56
57 b = Button(toolbar, text="Boton1", width=6, command=boton1)
58 b.pack(side=LEFT, padx=2, pady=2)
59
60 b = Button(toolbar, text="Boton2", width=6, command=boton2)
61 b.pack(side=LEFT, padx=2, pady=2)
62
63 b = Button(toolbar, text="Boton3", width=6, command=boton3)
64 b.pack(side=LEFT, padx=2, pady=2)
65
66 b = Button(toolbar, text="Nueva Ventana", width=15, command=boton4)
67 b.pack(side=LEFT, padx=2, pady=2)
68
69 b = Button(toolbar, text="Salir", width=6, command='exit')
70 b.pack(side=LEFT, padx=2, pady=2)
71
72 toolbar.pack(side=TOP, fill=X)
73
74
75
76 menu = Menu(root)
77 root.config(menu=menu)
78 filemenu = Menu(menu)
79 menu.add_cascade(label="Archivo", menu=filemenu)
80 filemenu.add_command(label="Nuevo", command=nuevo)
81 filemenu.add_command(label="Abrir...", command=abrir)
82 filemenu.add_command(label="Guardar", command=guardar)
83 filemenu.add_separator()
84 filemenu.add_command(label="Salir", command='exit')
85
86 root.mainloop()