python-3.x - 继承父窗口并在 tkinter 中添加一个附加按钮?
问题描述
我正在尝试创建两个单独的窗口,其中一个应该继承其他界面,并网格化一些额外的按钮。我怎样才能做到这一点?下面是一段示例代码:
f = ("Helvetica", 18)
bg = 'white'
g = '1400x800'
class MainUser(Frame):
def __init__(self, master):
Frame.__init__(self, master)
Frame.configure(self, background='white')
self.logo = PhotoImage(file="logo.gif")
Label(self, image=self.logo).pack()
Button(self, text='test', bg=bg, font=f).pack()
class MainAdmin(MainUser):
pass # What now?
解决方案
您只需要创建一个__init__
在超类中调用相同函数的属性。然后,像在超类中那样添加小部件。
例子:
class MainAdmin(MainUser):
def __init__(self, master):
super().__init__(master)
another_label = Label(self, text="Hello from MainAdmin")
another_label.pack(side="top", fill="x")
推荐阅读
- javascript - 使用箭头函数和不使用箭头有什么区别?(feat.React)[编辑]
- python - 构造字符串以粘贴到谷歌表格中的多个单元格中
- javascript - Zapier 将对象数组分解为包含对象键的不同数组
- java - Javaagent 抛出 java.lang.NoClassDefFoundError: java/sql/PreparedStatement with java 15
- excel - 运行时错误 1004 VBA - for 循环的第二个实例上的 VLookup?
- string - 错误:原因:java.lang.NumberFormatException:对于输入字符串:“3,00”
- python - 在重复索引的情况下如何从 DataFrame 中获取唯一计数
- asp.net - 如何禁用浏览器跟踪它的窗口是否正在使用的能力?
- r - 如何编写 R 代码以在行中打印数字模式,如下所示:
- c++ - 在编译时解析配置文件 [C++]