在 Main Window 中单击按钮后,第二个 Window 为空白
Second Window is blank after a button was clicked in Main Window
我有两个 python 文件,第一个包含主要 Window,第二个 python 文件包含另一个 Window。我设法使第二个 window 出现,但 window 出现后是空白的。这是错误的屏幕截图。
这里是点击 "Configuration" 按钮后应该显示的内容。
在主 window 文件中,我这样定义代码:
from tkinter import *
import configureUAHChange as cA
class TracingInterface(Frame):
def __init__(self, master):
super().__init__()
root.minsize(width=700, height=520)
root.maxsize(width=700, height=520)
Frame.__init__(self, master)
Grid.config(self)
self.TracingMethod()
self.logDetails()
self.otherFunctionInterface()
# Default window state
self._configureUA_window = None
def UAconfig_window(self):
if self._configureUA_window is not None:
return
self._configureUA_window =cA.ConfigureUAinterface(self)
def closeUA(self):
# Destroy the 2nd and reset the value to None
if self._configureUA_window is not None:
self._configureUA_window.destroy()
self._configureUA_window = None
此行用于按钮单击命令:
self.configUAButton = Button(self.radioframe, text="Configuration",command=self.UAconfig_window)
接下来,这就是我在第二个 python 文件中定义函数的方式
class ConfigureUAinterface(Toplevel):
def __init__(self, master):
super().__init__(master)
master.minsize(width=700, height=520)
master.maxsize(width=700, height=520)
Frame.__init__(self, master)
Grid.config(self)
master.title("UA Configuration")
#Pre define combobox value in case suggestion
self.value_of_combo='Identity Theft'
#Run the all Function
self.DateSelection()
self.finish()
self.UASuggestion()
self.ConfigurationUA()
self.suggestionCombo()
请告诉我如何修改我的代码来解决上述错误。
这是主要的完整编码 window :https://drive.google.com/open?id=1KKgYPbGMNNWBfPVazHfcM_NSFlv5eEpKg3_uXsvQsNE
这是第二个的完整编码 window:https://drive.google.com/open?id=1LuqJXIUrDMLfuz8gnZynZXUN6-SvFAyw9c-puJ3REPQ
1)我觉得TracingInterface
的__init__
函数中有一些root
应该是master
。
2) 你传递给 ConfigureUAinterface
的母版不是 window 而是 TracingInterface
是一个框架并且没有 minsize
, maxsize
和 title
方法。
3) 我不知道你为什么使用 Frame.__init__(self, master)
而 ConfigureUAinterface
继承自 Toplevel
.
编辑:
主要变化 window:
class TracingInterface(Frame):
def __init__(self, master):
super().__init__()
# 1) master instead of root (it was just a typo I think)
master.minsize(width=700, height=520)
master.maxsize(width=700, height=520)
# Frame.__init__(self, master): redundant with super().__init__()
Grid.config(self)
self.TracingMethod()
self.logDetails()
self.otherFunctionInterface()
# Default window state
self._configureUA_window = None
def UAconfig_window(self):
if self._configureUA_window is not None:
return None
# 2) changed self which is a frame to the actual window self.master
self._configureUA_window = cA.ConfigureUAinterface(self.master)
第二次更改 window:
class ConfigureUAinterface(Toplevel):
def __init__(self, master):
super().__init__(master)
# replaced master by self since it's the Toplevel size we want to limit
self.minsize(width=700, height=520)
self.maxsize(width=700, height=520)
# 3) The following is inapropriate since the widget
# inherit from Toplevel, not Frame:
# Frame.__init__(self, master)
# Grid.config(self)
# replaced master by self since it's the Toplevel title
self.title("UA Configuration")
#Pre define combobox value in case suggestion
self.value_of_combo='Identity Theft'
#Run the all Function
self.DateSelection()
self.finish()
self.UASuggestion()
self.ConfigurationUA()
self.suggestionCombo()
我没有修改代码中的任何其他内容,当我尝试时,它成功了。
我有两个 python 文件,第一个包含主要 Window,第二个 python 文件包含另一个 Window。我设法使第二个 window 出现,但 window 出现后是空白的。这是错误的屏幕截图。
这里是点击 "Configuration" 按钮后应该显示的内容。
在主 window 文件中,我这样定义代码:
from tkinter import *
import configureUAHChange as cA
class TracingInterface(Frame):
def __init__(self, master):
super().__init__()
root.minsize(width=700, height=520)
root.maxsize(width=700, height=520)
Frame.__init__(self, master)
Grid.config(self)
self.TracingMethod()
self.logDetails()
self.otherFunctionInterface()
# Default window state
self._configureUA_window = None
def UAconfig_window(self):
if self._configureUA_window is not None:
return
self._configureUA_window =cA.ConfigureUAinterface(self)
def closeUA(self):
# Destroy the 2nd and reset the value to None
if self._configureUA_window is not None:
self._configureUA_window.destroy()
self._configureUA_window = None
此行用于按钮单击命令:
self.configUAButton = Button(self.radioframe, text="Configuration",command=self.UAconfig_window)
接下来,这就是我在第二个 python 文件中定义函数的方式
class ConfigureUAinterface(Toplevel):
def __init__(self, master):
super().__init__(master)
master.minsize(width=700, height=520)
master.maxsize(width=700, height=520)
Frame.__init__(self, master)
Grid.config(self)
master.title("UA Configuration")
#Pre define combobox value in case suggestion
self.value_of_combo='Identity Theft'
#Run the all Function
self.DateSelection()
self.finish()
self.UASuggestion()
self.ConfigurationUA()
self.suggestionCombo()
请告诉我如何修改我的代码来解决上述错误。
这是主要的完整编码 window :https://drive.google.com/open?id=1KKgYPbGMNNWBfPVazHfcM_NSFlv5eEpKg3_uXsvQsNE
这是第二个的完整编码 window:https://drive.google.com/open?id=1LuqJXIUrDMLfuz8gnZynZXUN6-SvFAyw9c-puJ3REPQ
1)我觉得TracingInterface
的__init__
函数中有一些root
应该是master
。
2) 你传递给 ConfigureUAinterface
的母版不是 window 而是 TracingInterface
是一个框架并且没有 minsize
, maxsize
和 title
方法。
3) 我不知道你为什么使用 Frame.__init__(self, master)
而 ConfigureUAinterface
继承自 Toplevel
.
编辑: 主要变化 window:
class TracingInterface(Frame):
def __init__(self, master):
super().__init__()
# 1) master instead of root (it was just a typo I think)
master.minsize(width=700, height=520)
master.maxsize(width=700, height=520)
# Frame.__init__(self, master): redundant with super().__init__()
Grid.config(self)
self.TracingMethod()
self.logDetails()
self.otherFunctionInterface()
# Default window state
self._configureUA_window = None
def UAconfig_window(self):
if self._configureUA_window is not None:
return None
# 2) changed self which is a frame to the actual window self.master
self._configureUA_window = cA.ConfigureUAinterface(self.master)
第二次更改 window:
class ConfigureUAinterface(Toplevel):
def __init__(self, master):
super().__init__(master)
# replaced master by self since it's the Toplevel size we want to limit
self.minsize(width=700, height=520)
self.maxsize(width=700, height=520)
# 3) The following is inapropriate since the widget
# inherit from Toplevel, not Frame:
# Frame.__init__(self, master)
# Grid.config(self)
# replaced master by self since it's the Toplevel title
self.title("UA Configuration")
#Pre define combobox value in case suggestion
self.value_of_combo='Identity Theft'
#Run the all Function
self.DateSelection()
self.finish()
self.UASuggestion()
self.ConfigurationUA()
self.suggestionCombo()
我没有修改代码中的任何其他内容,当我尝试时,它成功了。