python - 按钮不显示在框架中
问题描述
我已经创建了几个框架,现在想在它们上面放置一些按钮和标签,但是从我创建的第一个按钮开始,我遇到了一个问题。tkinter 窗口中没有显示任何内容。
from tkinter import *
class STproject():
def __init__(self,app): #1
self.stframe=Frame(app,background='blue',height=90,width=350)
self.stframe.grid(row=0,column=0)
self.ndframe=Frame(app,background='red',height=90,width=350)
self.ndframe.grid(row=1,column=0)
self.rdframe=Frame(app,background='yellow',height=90,width=350)
self.rdframe.grid(row=2,column=0)
self.ndstframe=Frame(self.ndframe,background='black',width=145)
self.ndstframe.grid(row=0,column=0,rowspan=3,sticky='ns')
self.ndndframe=Frame(self.ndframe,background='white',height=45,width=205)
self.ndndframe.grid(row=1,column=1)
self.ndrdframe=Frame(self.ndframe,background='green',height=45,width=205)
self.ndrdframe.grid(row=2,column=1)
def buttons(self):
self.importbutton=Button(self.stframe,text='Import',width=4,height=2)
self.importbutton.grid(row=0,column=0)
root=Tk()
root.title('SteelBox Inc. Calculator')
application=STproject(root) #2
root.mainloop() #3
解决方案
您已将按钮的创建放在一个单独的函数中,但您从未调用它。添加self.buttons()
在末尾,__init__
按钮将出现。
推荐阅读
- amazon-web-services - Dynomodb 的 Amazon Api Gateway 服务代理
- java - 编写正则表达式模式以便于理解/维护?
- jquery - 对特定列进行排序不起作用 - jquery Datatables
- react-native - 打开另一个屏幕 React-navigation 3.. flatlist
- import - 导入 SQL Google Cloud SQL:HTTPError 403:权限不足
- python - 获取包含修饰函数的文件的路径
- keras - 定义具有附加权重的自定义 keras 层时如何使用 GRUCell?
- python - Tensorflow/Keras:模型的输出层期望的输入形状与它收到的不同
- sql - SQL的列级加密在哪里使用?
- css - svg中的响应式图像