Python关于tkinter模块中类的三种继承方式示例分享


当前第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()

  #MyApp().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模块中类的三种继承方式示例分享的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

unity3d能用Python写吗

Python在哪里下载

Python 匹配url中是否存在ip地址的方法

Python统计单词出现次数

Python在excel中的应用是什么

Python 怎么把列表的[]去掉

Python 按照固定长度分割字符串的方法

一分钟了解Python中“*”的作用

Python语言的面向对象编程的介绍(附代码)

给大家分享一下日常学习Python的心得(详解)

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...