Draw an user interface with TKinter
//TEST 1//
from Tkinter import *
class test:
def __init__(self,master):
frame=Frame(master);
frame.pack()
self.bt_quit=Button(frame,text="QUIT",fg="red",command=frame.quit)
self.bt_quit.pack(side=LEFT)
self.bt_hello=Button(frame,text="HELLO",command=self.say_hello)
self.bt_hello.pack(side=RIGHT)
def say_hello(self):
print"Hello World"
root=Tk()
tkintest=test(root)
root.mainloop()
//TEST 2//
from Tkinter import *
class test:
def __init__(self,master):
frame=Frame(master);
frame.pack()
self.bt_quit=Button(frame,text="QUIT",fg="red",command=frame.quit)
self.bt_quit.pack(side=LEFT)
self.frame=Frame(root,width=100,height=100)
self.frame.bind("<Button-1>",self.callback)
self.frame.pack()
def callback(self, event):
print"clicked at",event.x,event.y
root=Tk()
tkintest=test(root)
root.mainloop()
//TEST 3//
from Tkinter import *
import tkMessageBox
def callback():
if (tkMessageBox.askokcancel("Quit","Do you really want to quit?")):
root.destroy()
root=Tk()
root.protocol("WM_DELETE_WINDOW",callback)
root.mainloop()
//TEST 4//
from Tkinter import *
import tkMessageBox
def callback():
tkMessageBox.showinfo("Hello","This is a test")
root=Tk()
menu=Menu(root)
root.config(menu=menu)
filemenu=Menu(menu)
menu.add_cascade(label="File",menu=filemenu)
filemenu.add_command(label="Start", command=callback)
filemenu.add_command(label="Open", command=callback)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
helpmenu=Menu(menu)
menu.add_cascade(label="Help",menu=helpmenu)
helpmenu.add_command(label="About",command=callback)
root.mainloop()