每次尝试调整窗口大小时,我们都试图重新绘制一个窗口,这已从当前代码中删除:
def draw_frames(self):
self.subFrameLeft = Frame(self.name, bg=LightGray, height=self.height /
2, width=self.width / 2 - 5,
relief=RAISED)
self.subFrameRight = Frame(self.name, bg=LightGray, height=self.height /
2, width=self.width / 2 - 5,
relief=RAISED)
self.subFrameBottom = Frame(self.name, bg="#3C3F41", height=self.height
/ 3, width=self.width, relief=RAISED)
self.abortButton = Button(self.subFrameBottom, text="ABORT MISSION",
state=self.abort_button_state, bg="red",
command=self.abort_message_callback,
width=int(20/600 * self.width),
height=int(1.5/600 * self.height))
self.statusLabel = Label(self.subFrameBottom,
text=self.status_label_text, fg=self.status_label_text_color,
bg="#808080", width= int(20/600 * self.width),
height=int(2/600 * self.width))
self.subFrameLeft.place(x=0, y=5)
self.subFrameRight.place(x=self.width / 2 + 5, y=5)
self.subFrameBottom.place(x=0, y=self.height * 315 / 600)
self.add_frame_features()
def destroy_frames(self):
self.subFrameLeft.destroy()
self.subFrameRight.destroy()
self.subFrameBottom.destroy()
def update_size(self):
self.width = self.name.winfo_width()
self.height = self.name.winfo_height()
self.destroy_frames()
self.draw_frames()
root = Tk()
p = MyWindow(root)
def d(event):
p.update_size()
root.bind('<Configure>',d)
root.mainloop()
当前,该程序在启动时出现段错误,可以通过注释掉self.destroy_frames()进行补救,但是之后它们会相互重叠。有关如何解决此问题的任何建议将大有帮助。