【发布时间】:2021-04-03 12:21:37
【问题描述】:
我遇到了 wx.panels 的问题。 在我的项目中创建了一个文件,其中 wx.frame 在文件中的一个类中继承,其他两个文件继承了 wx.panels。 我试图隐藏/销毁 panel1 并调用 panel2 但不知何故它不起作用。开关上会出现一个带有面板背景颜色的小方形图标。 我在stackoverflow上提到了[this topic][1],但我发现如果我不使用sizer,代码就不起作用(在不同的文件中拆分时。) [1]:https://stackoverflow.com/questions/58794753/wxpython-panel-is-cropped-with-only-a-small-box-shown-at-the-top-left-hand-corne
main.py
import sys
import wx
from test1 import panel1
from test2 import panel2
class main(wx.Frame):
def __init__(self,*args, **kwargs):
super().__init__(*args, **kwargs)
self.panel = panel1(parent=self)
self.Show()
# display=wx.Display()
# size = display.GetGeometry().GetSize()
# print(size)
def update_window(self):
self.panel2=panel2(self,wx.ID_ANY)
self.panel2.Show()
self.panel.Hide()
self.Refresh()
if __name__ == "__main__":
print(__file__)
app = wx.App() # Create a new app, don't redirect stdout/stderr to a window.
frame = main(None, wx.ID_ANY, "Hello World",size=(1024,700)) # A Frame is a top-level window.
frame.Show(True) # Show the frame.
app.MainLoop()
test1.py
import wx
from view.panel import custom_panel
from test2 import panel2
class panel1(custom_panel):
def __init__(self,parent=None):
super().__init__(parent)
self.parent=parent
self.btn1 = wx.Button(self,wx.ID_ANY,"button1",pos=(100,50),size=(300,50))
self.Bind(wx.EVT_BUTTON, self.On_btn1_clicked, self.btn1)
def On_btn1_clicked(self, event):
self.parent.update_window()
test2.py
import wx
from view.panel import custom_panel
class panel2(custom_panel):
def __init__(self,parent=None,id=None,size=(1024,700)):
super().__init__(parent)
self.parent=parent
self.btn2 = wx.Button(self,wx.ID_ANY,"button2",pos=(300,50),size=(300,50))
self.Bind(wx.EVT_BUTTON, self.On_btn2_clicked, self.btn2)
def On_btn2_clicked(self, event):
self.parent.update_window()
custom_panel.py
import wx
class custom_panel(wx.Panel):
def __init__(self,*args, **kwargs):
super().__init__(*args, **kwargs)
self.SetBackgroundColour("#000000")
if __name__ == "__main__":
pass
【问题讨论】:
-
请分享您用来处理问题的代码。
-
请立即查看帖子@AlexK。
标签: python user-interface wxpython wxwidgets