Tkinter Desktop
参考网站:http://effbot.org/tkinterbook
from Tkinter import * class App(object): def __init__(self,tk): frame=Frame(tk) frame.pack() self.button=Button(frame,text='close win',command=frame.quit) self.button.config(width=3,height=1,fg='red',bg='black')#属性配置 self.button.pack()#pack grid self.button1=Button(frame,text='sayhi',command=self.sayhi)#事件 event bind self.button1.pack() def sayhi(self): print('hello world..') root=Tk() app=App(root) root.mainloop()
#menu
from Tkinter import * def sayhi(): print('hello world..') root=Tk() menu=Menu(root) root.config(menu=menu) filemenu=Menu(menu) menu.add_cascade(label='File',menu=filemenu) filemenu.add_command(label='New',command=sayhi) filemenu.add_command(label='Open',command=sayhi) helpmenu=Menu(menu) menu.add_cascade(label='Help',menu=helpmenu) helpmenu.add_command(label='Help',command=sayhi) helpmenu.add_command(label='About',command=sayhi) root.mainloop()
#event
from Tkinter import * import tkMessageBox def sayhi(event): frame.focus_set() print(event.x,event.y) def closewin(): if tkMessageBox.askokcancel('quit','yes or no'): root.destroy() root=Tk() frame=Frame(root,width=50,height=25) frame.bind('<Button-1>',sayhi) frame.pack() root.protocol('WM_DELETE_WINDOW',closewin) root.mainloop()