码迷,mamicode.com
首页 > 其他好文 > 详细

Tkinter

时间:2017-11-07 14:30:09      阅读:184      评论:0      收藏:0      [点我收藏+]

标签: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.

 

Tkinter

标签:yourself   real   desc   ant   word   creation   automatic   size   instance   

原文地址:http://www.cnblogs.com/gipagod/p/7798503.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!