import Tkinter
class Test:
def __init__(self,master):
frame=Tkinter.Frame(master)
frame.pack()
self.button=Tkinter.Button(frame,text='Quit',fg='red',command=frame.quit)
self.button.pack(side='left')
self.hi_there=Tkinter.Button(frame,text='hello',command=self.say_hi)
self.hi_there.pack(side='left')
def say_hi(self):
print 'hi there, this is a test!'
win=Tkinter.Tk()
Test=Test(win)
win.mainloop()
from Tkinter import *
root=Tk()
def hello():
print 'hello'
menubar=Menu(root)
menubar.add_command(label='hello',command=hello)
menubar.add_command(label='quit',command=root.quit)
root.config(menu=menubar)
mainloop()
from Tkinter import *
root=Tk()
def hello():
print 'hello'
def about():
w=Label(root,text='hello,test')
w.pack(side='top')
menubar=Menu(root)
filemenu=Menu(menubar,tearoff=0)
filemenu.add_command(label='Open',command=hello)
filemenu.add_command(label='Save',command=hello)
filemenu.add_separator()
filemenu.add_command(label='Exit',command=root.quit)
menubar.add_cascade(label='File',menu=filemenu)
filemenu2=Menu(menubar,tearoff=0)
filemenu2.add_command(label='Open',command=hello)
filemenu2.add_command(label='Save',command=hello)
menubar.add_cascade(label='Edit',menu=filemenu2)
filemenu3=Menu(menubar,tearoff=0)
filemenu3.add_command(label='About',command=about)
menubar.add_cascade(label='Help',menu=filemenu3)
root.config(menu=menubar)
mainloop()
reference:
http://www.yiibai.com/python/python_gui_programming.html
class Test:
def __init__(self,master):
frame=Tkinter.Frame(master)
frame.pack()
self.button=Tkinter.Button(frame,text='Quit',fg='red',command=frame.quit)
self.button.pack(side='left')
self.hi_there=Tkinter.Button(frame,text='hello',command=self.say_hi)
self.hi_there.pack(side='left')
def say_hi(self):
print 'hi there, this is a test!'
win=Tkinter.Tk()
Test=Test(win)
win.mainloop()
from Tkinter import *
root=Tk()
def hello():
print 'hello'
menubar=Menu(root)
menubar.add_command(label='hello',command=hello)
menubar.add_command(label='quit',command=root.quit)
root.config(menu=menubar)
mainloop()
from Tkinter import *
root=Tk()
def hello():
print 'hello'
def about():
w=Label(root,text='hello,test')
w.pack(side='top')
menubar=Menu(root)
filemenu=Menu(menubar,tearoff=0)
filemenu.add_command(label='Open',command=hello)
filemenu.add_command(label='Save',command=hello)
filemenu.add_separator()
filemenu.add_command(label='Exit',command=root.quit)
menubar.add_cascade(label='File',menu=filemenu)
filemenu2=Menu(menubar,tearoff=0)
filemenu2.add_command(label='Open',command=hello)
filemenu2.add_command(label='Save',command=hello)
menubar.add_cascade(label='Edit',menu=filemenu2)
filemenu3=Menu(menubar,tearoff=0)
filemenu3.add_command(label='About',command=about)
menubar.add_cascade(label='Help',menu=filemenu3)
root.config(menu=menubar)
mainloop()
reference:
http://www.yiibai.com/python/python_gui_programming.html