好的,在这一个人的头上撞墙。这已被问过几次并且多次回答。但是,在我的情况下,这些修复工作不正常,迫切需要一些帮助。这是我正在使用的; Raspberry pi 3,python 3.4。
问题是在启动时使用代码最大化应用程序,两个窗口打开!! Arhg!一个完全空白的窗口打开全屏,我的应用程序也打开但未触动。我确定有一些愚蠢的我失踪但是我已经在墙上撞了几天了哈哈。
这是我的完整代码任何帮助将非常感谢!!
import tkinter as tk
from tkinter import ttk
LARGE_FONT=("Impact", 12, "bold")
class TESOSapp (tk.Tk):
def __init__(self, *args,**kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, "Thrive Energy Systems")
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (SystemRun, ManualRun, SystemSettings, Diagnostics):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column = 0, sticky="nsew")
self.show_frame(SystemRun)
def show_frame(self,cont):
frame = self.frames[cont]
frame.tkraise()
class SystemRun(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
frame = tk.Frame(self)
frame.grid(rowspan=8, columnspan=4)
label = tk.Label(self, width=100, height=1)
label.grid(row=0, column=0, rowspan=1, columnspan=4)
#Menu
Menu1=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="SYSTEM RUN", bg='dark gray', command=lambda: controller.show_frame(SystemRun))
Menu1.grid(row=1, column=0)
Menu2=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="MANUAL RUN", bg='dark gray', command=lambda: controller.show_frame(ManualRun))
Menu2.grid(row=1, column=1)
Menu3=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="SYSTEM SETTINGS", bg='dark grey', command=lambda: controller.show_frame(SystemSettings))
Menu3.grid(row=1, column=2)
Menu4=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="DIAGNOSTICS", bg='dark gray', command=lambda: controller.show_frame(Diagnostics))
Menu4.grid(row=1, column=3)
label = tk.Label(self, width=100, height=1)
label.grid(row=2, columnspan=4)
#Buttons
CycleRun=tk.Button(self, width=16, height=2,
font=("Impact", 12, "italic", "bold"),
text="CYCLE RUN", bg='darkorange')
CycleRun.grid(row=3, column=0)
CycleRun=tk.Button(self, width=16, height=2,
font=("Impact", 12, "italic", "bold"),
text="SERVICE MODE", bg='darkorange')
CycleRun.grid(row=4, column=0)
CycleRun=tk.Button(self, width=16, height=2,
font=("Impact", 12, "italic", "bold"),
text="AUTOMATIC OVERIDE", bg='darkorange')
CycleRun.grid(row=5, column=0)
CycleRun=tk.Button(self, width=16, height=2,
font=("Impact", 12, "italic", "bold"),
text="SYSTEM SHUTDOWN", bg='darkorange')
CycleRun.grid(row=6, column=0)
class ManualRun(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
frame = tk.Frame(self)
frame.grid(rowspan=8, columnspan=4)
label = tk.Label(self, width=16, height=1)
label.grid(row=0, columnspan=4)
#Menu
Menu1=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="SYSTEM RUN", command=lambda: controller.show_frame(SystemRun))
Menu1.grid(row=0, column=0)
Menu2=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="MANUAL RUN", command=lambda: controller.show_frame(ManualRun))
Menu2.grid(row=0, column=1)
Menu3=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="SYSTEM SETTINGS", command=lambda: controller.show_frame(SystemSettings))
Menu3.grid(row=0, column=2)
Menu4=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="DIAGNOSTICS", command=lambda: controller.show_frame(Diagnostics))
Menu4.grid(row=0, column=3)
class SystemSettings(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
frame = tk.Frame(self)
frame.grid(rowspan=8, columnspan=4)
label = tk.Label(self, width=16, height=1)
label.grid(row=0, columnspan=4)
#Menu
Menu1=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="SYSTEM RUN", command=lambda: controller.show_frame(SystemRun))
Menu1.grid(row=0, column=0)
Menu2=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="MANUAL RUN", command=lambda: controller.show_frame(ManualRun))
Menu2.grid(row=0, column=1)
Menu3=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="SYSTEM SETTINGS", command=lambda: controller.show_frame(SystemSettings))
Menu3.grid(row=0, column=2)
Menu4=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="DIAGNOSTICS", command=lambda: controller.show_frame(Diagnostics))
Menu4.grid(row=0, column=3)
class Diagnostics(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
frame = tk.Frame(self)
frame.grid(rowspan=8, columnspan=4)
label = tk.Label(self, width=16, height=1)
label.grid(row=0, columnspan=4)
#Menu
Menu1=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="SYSTEM RUN", command=lambda: controller.show_frame(SystemRun))
Menu1.grid(row=0, column=0)
Menu2=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="MANUAL RUN", command=lambda: controller.show_frame(ManualRun))
Menu2.grid(row=0, column=1)
Menu3=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="SYSTEM SETTINGS", command=lambda: controller.show_frame(SystemSettings))
Menu3.grid(row=0, column=2)
Menu4=tk.Button(self, width=16, height=1,
font=("Impact", 12, "italic", "bold"),
text="DIAGNOSTICS", command=lambda: controller.show_frame(Diagnostics))
Menu4.grid(row=0, column=3)
root = tk.Tk()
root.attributes('-zoomed', True)
root.wm_title('Thrive Energy Systems')
app= TESOSapp()
app.mainloop()
答案 0 :(得分:0)
将-fullscreen添加到root.attributes
所以:
root.attributes('-zoomed', '-fullscreen', True) # This may be wrong
答案 1 :(得分:0)
你正在两次调用Tk(),因此你得到2个窗口。由于您的TESOSapp类继承自Tk,因此您可以将其视为root。因此,简单的解决方法是将底部更改为:
app=TESOSapp()
app.attributes('-zoomed', True)
app.wm_title('Thrive Energy Systems')
app.mainloop()
在我看来,更好的解决方法是始终从Frame继承,而不是Tk。
class TESOSapp (tk.Frame):
def __init__(self, *args,**kwargs):
tk.Frame.__init__(self, *args, **kwargs)
app= TESOSapp(root)