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


本文摘自php中文网,作者黄舟,侵删。

这篇文章主要介绍了Python tkinter模块中类继承的三种方式,结合实例形式分析了三种继承方式的实现方法与相关注意事项,需要的朋友可以参考下

本文实例讲述了Python tkinter模块中类继承的三种方式。分享给大家供大家参考,具体如下:

tkinter class继承有三种方式。

提醒注意这几种继承的运行方式

一、继承 object

1.铺tk.Frame给parent:

说明:

self.rootframe = tk.Frame(parent)
tk.Label(self.rootframe)


1

2

3

4

5

6

7

8

9

10

11

12

import tkinter as tk

class MyApp(object):

  def __init__(self, parent):

    self.rootframe = tk.Frame(parent)

    self.rootframe.pack()

    self.setupUI()

  def setupUI(self):

    tk.Label(self.rootframe, text='标签').pack()

if __name__ == '__main__':

  root = tk.Tk()

  MyApp(root) # 注意这句

  root.mainloop()

2.直接使用root

说明:

self.root = parent
tk.Label(self.root)


1

2

3

4

5

6

7

8

9

10

11

12

import tkinter as tk

class MyApp(object):

  def __init__(self, parent, **kwargs):

    self.root = parent

    self.root.config(**kwargs)

    self.setupUI()

  def setupUI(self):

    tk.Label(self.root, text = '标签').pack()

if __name__ == '__main__':

  root = tk.Tk()

  app = test(root)

  root.mainloop()

二、继承 tk.Tk


阅读剩余部分

相关阅读 >>

Python介绍嵌套 json 秒变 dataframe!

Python可以运行在jvm上吗

Python怎么安装gdal

Python可以做动图吗

Python如何读取sqlite数据库的文件?

使用pandas进行数据处理之 dataframe篇

Python水仙花数的编程代码如何写

Python中迭代器与迭代器切片的详细介绍

Python dict怎么实现的

Python如何读取txt文件

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




打赏

取消

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

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

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

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

评论

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