当前第2页 返回上一页
1 2 3 4 5 6 7 8 9 | import tkinter as tk
class MyApp(tk.Tk):
def __init__( self ):
super ().__init__()
self .setupUI()
def setupUI( self ):
tk.Label( self , text = '标签' ).pack()
if __name__ = = '__main__' :
MyApp().mainloop()
|
三、继承 tk.Frame
分两种情况
1.有parent
1 2 3 4 5 6 7 8 9 10 11 | import tkinter as tk
class MyApp(tk.Frame):
def __init__( self , parent = None ):
super ().__init__(parent)
self .pack()
self .setupUI()
def setupUI( self ):
tk.Label( self , text = '标签' ).pack()
if __name__ = = '__main__' :
MyApp(tk.Tk()).mainloop()
|
注意: self.pack()
2.没有parent
1 2 3 4 5 6 7 8 9 10 | import tkinter as tk
class MyApp(tk.Frame):
def __init__( self ):
super ().__init__()
self .pack()
self .setupUI()
def setupUI( self ):
tk.Label( self , text = '标签' ).pack()
if __name__ = = '__main__' :
MyApp().mainloop()
|
以上就是Python关于tkinter模块中类的三种继承方式示例分享的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python中*的用法介绍(代码示例)
Python程序如何快速缩进多行代码
Python如何把数字变成日期
Python如何运行一个Python程序
Python续行符是什么
Python函数中如何返回多个值?(代码示例)
初中生如何学习Python
Python实现客户端和服务器端传输图片的代码
Python爬虫图片、操作excel
Python 中的int()函数怎么用
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python关于tkinter模块中类的三种继承方式示例分享