Python GUI生成器

用户名

我是Python的新手,但不是编程的人。本教程中,作者将在他的类中初始化一个构造函数,如下所示:

class simpleapp_tk(Tkinter.Tk):
    def __init__(self,parent):
        Tkinter.Tk.__init__(self,parent) 

我了解这一点,您在C#和Java中也是如此。但是,在本教程中,作者为什么不做同样的事情?他只初始化应用程序。像这样:

app = Tk()

在什么情况下,我会在第二种情况下进行第二种?您认为哪个更好?

用户4956086

个人而言,我总是做第二件事,因为当您制作更长的应用程序时,它会容易得多。这是使用第二个示例:

from Tkinter import *

app = Tk()    #app is a variable, so in the future, you can define Tk() as anything you want. Most people call it root
frame = Frame(app)
frame.pack()

bottomframe = Frame(app)
bottomframe.pack( side = BOTTOM )

redbutton = Button(frame, text="Red", fg="red")
redbutton.pack( side = LEFT)

greenbutton = Button(frame, text="Brown", fg="brown")
greenbutton.pack( side = LEFT )

bluebutton = Button(frame, text="Blue", fg="blue")
bluebutton.pack( side = LEFT )

blackbutton = Button(bottomframe, text="Black", fg="black")
blackbutton.pack( side = BOTTOM)

app.mainloop()

祝你好运。抱歉,我无法完全回答您的问题

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章