标签:yourself real desc ant word creation automatic size instance
from tkinter import * class App: def __init__(self, master): frame = Frame(master) frame.pack() self.button = Button( frame, text="QUIT", fg="red", command=frame.quit ) self.button.pack(side=LEFT) self.hi_there = Button(frame, text="Hello", command=self.say_hi) self.hi_there.pack(side=LEFT) def say_hi(self): print "hi there, everyone!" root = Tk() app = App(root) root.mainloop() root.destroy() # optional; see description below
More on wibget names
No matter ‘hi_there‘ or ‘button‘ in the example code up there, both of them are just references of the instance of the Button Class. In other words, they aren‘t the real names of the widgets. Since python needs their real names, it assigns them automatically. You can get the real names by using str(reference_name) , and of course you can assign by yourself if you want, for that you just need pass the argument ‘name", for example:
but = Button(root, name=‘Mybutton‘)
then "Mybutton" will be the real name of the widget. However the argument "name" is a ‘creation only‘ option, that means you cann‘t change it once you have created the widget.
标签:yourself real desc ant word creation automatic size instance
原文地址:http://www.cnblogs.com/gipagod/p/7798503.html