我正在使用 tkinter 在 python 中为 brainf*ck 制作一个 ide,我正在添加一个最近的项目部分,但是当我放置按钮时,它们不会出现在屏幕上。这是代码Scene:from tkinter import *from tkinter import filedialog as Fileimport tkinter as tkclass HoverButton(tk.Button): def __init__(self, master, **kw): tk.Button.__init__(self, master=master, **kw) self.defaultBackground = "#5d5d5d" self['background'] = self.defaultBackground self['activebackground'] = "#6d6d6d" self.bind("<Enter>", self.on_enter) self.bind("<Leave>", self.on_leave) def on_enter(self, e): self['background'] = "#6d6d6d" def on_leave(self, e): self['background'] = self.defaultBackgroundclass ProjectPage(Frame): def __init__(self, master, projects=[]): super().__init__(master) self.projects = projects self.buttons = [] self.mstr = self.master.master self.title = "PesolIde: Projets" self.width = 800 self.height = 500 self.color = "#4d4d4d" self.projectFrame = tk.Frame(self.mstr,width=800,height=50,bg="#5d5d5d") self.newProject = HoverButton(self.mstr,text="New Project", height=1, bg="#6d6d6d") self.openProject = HoverButton(self.mstr,text="Open Project", height=1,bg="#6d6d6d", command=OpenAsk) self.projectdisplay = tk.Frame(self.mstr, width=700, height=300, bg="#5d5d5d", highlightbackground="black", highlightthickness=1) for i in range(len(self.projects)): self.buttons.append(HoverButton(master, text=self.projects[i].split(':')[0], width=50, height=1)) if len(self.buttons)>=40: break self.loaded = False def show(self): self.projectFrame.place(x=0, y=0) self.newProject.place(x=20, y=10) self.openProject.place(x=120, y=10) self.projectdisplay.place(x=50,y=100) self.y = 100当我在文件中创建类HoverButton外部时,它会按预期显示,但在直接从主文件的类中初始化时不会出现。ProjectPageProjectPageProjectPage使用左侧代码从类外运行的输出:
1 回答
MYYA
TA贡献1868条经验 获得超4个赞
尝试插入 relx、rely、relwidth、relheight 的值作为“place”中的属性,或者您也可以插入 height、width 作为 place 的属性。
添加回答
举报
0/150
提交
取消