所以,我正在尝试为我分配的项目制作这个程序。代码仍然是草稿,当我被分配这个项目时,我真的对wxPython一无所知。
反正。这个程序的功能是创建一个管理相册的应用程序。我得到它来创建/删除文件夹,并能够更改其根目录并将程序文件移动到其他地方。我还得到了为每张专辑生成位图按钮的功能。并将它们放在FlexGridSizer中。
我的问题是这些位图按钮无法点击。
class RightPanel(wx.Panel):
global path
def __init__(self, parent):
a = wx.GetDisplaySize()
width = 3 * a[0] / 4
height = 3 * a[1] / 4
wx.Panel.__init__(self, parent=parent,
size=(3*width/4, height),
style=wx.EXPAND)
self.SetBackgroundColour('dark grey')
self.widgetSizer = wx.BoxSizer(wx.VERTICAL)
class MasterPanel(wx.Panel):
global delete, CurrentDirg, locale
delete = False
a = wx.GetDisplaySize()
width = 3 * a[0] / 4
height = 3 * a[1] / 4
id = {}
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.MasterPanel = wx.Panel(self,
wx.ID_ANY,
size=(self.width, self.height),
)
self.SetBackgroundColour('light grey')
self.sizer = wx.BoxSizer(wx.VERTICAL)
splitter1 = wx.SplitterWindow(self)
splitter2 = wx.SplitterWindow(splitter1)
left_pt = LeftPanelTop(splitter2)
left_pb = LeftPanelBottom(splitter2)
self.rightP = RightPanel(splitter1)
self.boxsizer2 = wx.BoxSizer(wx.VERTICAL)
splitter2.SetSashGravity(0.5)
splitter2.SplitHorizontally(left_pt, left_pb)
splitter1.SplitVertically(splitter2, self.rightP)
splitter1.SetSashGravity(0.5)
self.gSizer = wx.FlexGridSizer(0, 5, 10, 10)
self.dir_search()
self.boxsizer2.Add(self.gSizer, 1, wx.EXPAND|wx.ALL)
self.rightP.SetSizer(self.boxsizer2)
self.boxsizer2.Layout()
self.sizer.Add(splitter1, 1, wx.EXPAND)
self.SetSizer(self.sizer)
def dir_search(self):
global path, delete
try:
if self.id != {} or delete == True:
sizer = self.gSizer
for i in sizer.GetChildren():
sizer.Hide(0)
sizer.Remove(0)
self.boxsizer2.Layout()
self.gSizer.Layout()
self.id = {}
with open('albums.dir', mode='r', buffering=1) as alb:
names = alb.readlines()
for i in range(len(names)):
names[i] = names[i].rstrip('\n')
paths = [path + '\\' + i for i in names]
counter = 0
for i in paths:
self.dirimcreate(i, counter)
counter += 1
print(self.id)
except Exception as E:
print(E)
sizer = self.gSizer
while sizer.GetChildren():
sizer.Hide(0)
sizer.Remove(0)
self.boxsizer2.Layout()
def dirimcreate(self, path, counter):
pic = wx.Image('input.ico', wx.BITMAP_TYPE_ANY)
pic = pic.Scale(self.width / 10, self.width / 10, wx.IMAGE_QUALITY_HIGH)
pic = pic.ConvertToBitmap()
self.saasda = wx.BitmapButton(self.rightP,
wx.ID_ANY,
pic,
size=(self.width / 10, self.width / 10),
style=wx.NO_BORDER
)
self.saasda.Bind(wx.EVT_BUTTON, self.chdir)
self.saasda.SetDefault()
self.saasda.myname = self.saasda.GetId()
self.id[self.saasda.GetId()] = path
self.gSizer.Add(self.saasda, 0, wx.ALL, 5)
self.boxsizer2.Layout()
def chdir(self, event):
self.Info(message='You clicked a button')
提前谢谢。
答案 0 :(得分:0)
我找到了解决方案!
似乎MasterPanel类的代码在init中包含了一个size参数,它创建了一个覆盖其他所有内容的不可见面板,使其无法点击。