我正在制作一个程序,为您提供可供选择的艺术家列表,当您点击艺术家时,它会打开一个新窗口,并为您提供他们的绘画选择。但是,当我尝试这样做时,新窗口上没有任何反应。我不能在它上面放任何按钮,甚至静态文本都不起作用,它在父窗口上工作得很好,但在子窗口上却不行。我错过了什么或者我是否需要完全做其他事情?这是我的代码:
import webbrowser
import sqlite3
import wx
conn = sqlite3.connect("dbPaintings.db")
c = conn.cursor()
c.execute("CREATE TABLE IF NOT EXISTS tblPaintings(Artist TEXT, PaintingName TEXT, Link TEXT)")
path = 'Artists Paintings.txt'
def insertingPaintings():
line = ''
filePaintings=open(path,'r')
for x in range(15):
arrPaintings = filePaintings.readline().split(",")
if len(arrPaintings) == 3:
strArtist = arrPaintings[0]
strPainting = arrPaintings[1]
strLink = arrPaintings[2]
strLink = strLink.split("\\")[0]
c.execute("INSERT INTO tblPaintings(Artist, PaintingName, Link) VALUES(:ArtistName, :Painting, :Url)", {'ArtistName':strArtist,'Painting':strPainting,'Url':strLink})
conn.commit()
#insertingPaintings()
class ArtFrame(wx.Frame):
def __init__(self, keyID, title, parent):
wx.Frame.__init__(self,parent=parent,title=title,size=(800,600))
panel = wx.Panel(self)
wx.StaticText(panel,-1,"Working",(566,345))
self.SetBackgroundColour('white')
if keyID=='Auguste Renoir':
self.AugusteRenoirWork()
def AugusteRenoirWork(self):
UmbrellasButtonImage = wx.Image('The Umbrellas.jpg',wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
UmbrellasButton = wx.BitmapButton(wx.Panel(self),-1,UmbrellasButtonImage,pos=(200,200),size=(200,250))
class MainFrame(wx.Frame):
def __init__(self,*args,**kwargs):
super(MainFrame, self).__init__(*args, **kwargs, size=(1280,720), style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX)
self.basicGUI()
self.Centre()
def basicGUI(self):
panel = wx.Panel(self)
self.SetBackgroundColour('black')
self.SetTitle('French Impressionism')
font=wx.Font(18, wx.DECORATIVE, wx.ITALIC, wx.NORMAL)
AugusteRenoirButtonImage = wx.Image('Auguste Renoir.jpg',wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
AugusteRenoirText = wx.StaticText(panel,-1,"Auguste Renoir",(237,345))
AugusteRenoirText.SetForegroundColour("#e6b800")
AugusteRenoirText.SetFont(font)
AugusteRenoirButton = wx.BitmapButton(panel,-1,AugusteRenoirButtonImage,pos=(220,85),size=(200,250))
self.Bind(wx.EVT_BUTTON,self.RenoirWindow,AugusteRenoirButton)
ClaudeMonetButtonImage = wx.Image('Claude Monet.jpg',wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
ClaudeMonetText = wx.StaticText(panel,-1,"Claude Monet",(566,345))
ClaudeMonetText.SetForegroundColour("#206020")
ClaudeMonetText.SetFont(font)
ClaudeMonetButton = wx.BitmapButton(panel,-1,ClaudeMonetButtonImage,pos=(540,85),size=(200,250))
self.Bind(wx.EVT_BUTTON,self.MonetWindow,ClaudeMonetButton)
VincentVanGoghButtonImage = wx.Image('Vincent Van Gogh.jpg',wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
VincentVanGoghText = wx.StaticText(panel,-1,"Vincent Van Gogh",(862,345))
VincentVanGoghText.SetForegroundColour("#3385ff")
VincentVanGoghText.SetFont(font)
VincentVanGoghButton = wx.BitmapButton(panel,-1,VincentVanGoghButtonImage,pos=(860,85),size=(200,250))
self.Bind(wx.EVT_BUTTON,self.VanGoghWindow,VincentVanGoghButton)
GeorgesSeuratButtonImage = wx.Image('Georges Seurat.jpg',wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
GeorgesSeuratText = wx.StaticText(panel,-1,"Georges Seurat",(393,640))
GeorgesSeuratText.SetForegroundColour("#990099")
GeorgesSeuratText.SetFont(font)
GeorgesSeuratButton = wx.BitmapButton(panel,-1,GeorgesSeuratButtonImage,pos=(380,380),size=(200,250))
self.Bind(wx.EVT_BUTTON,self.SeuratWindow,GeorgesSeuratButton)
PaulCezanneButtonImage = wx.Image('Paul Cezanne.jpg',wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
PaulCezanneText = wx.StaticText(panel,-1,"Paul Cezanne",(735,640))
PaulCezanneText.SetForegroundColour("#cc2900")
PaulCezanneText.SetFont(font)
PaulCezanneButton = wx.BitmapButton(panel,-1,PaulCezanneButtonImage,pos=(710,380),size=(200,250))
self.Bind(wx.EVT_BUTTON,self.CezanneWindow,PaulCezanneButton)
self.Show(True)
def RenoirWindow(self,event):
wx.Panel(self)
title = "Auguste Renoir's Works"
keyID='Auguste Renoir'
frame = ArtFrame(parent=wx.GetTopLevelParent(self),title=title,keyID=keyID)
frame.Show(True)
def MonetWindow(self,event):
wx.Panel(self)
title = "Claude Monet's Works"
keyID='Claude Monet'
frame = ArtFrame(parent=wx.GetTopLevelParent(self),title=title,keyID=keyID)
def VanGoghWindow(self,event):
wx.Panel(self)
title = "Vincent Van Gogh's Works"
keyID='Vincent Van Gogh'
frame = ArtFrame(parent=wx.GetTopLevelParent(self),title=title,keyID=keyID)
def SeuratWindow(self,event):
wx.Panel(self)
title = "Georges Seurat's Works"
keyID='Georges Seurat'
frame = ArtFrame(parent=wx.GetTopLevelParent(self),title=title,keyID=keyID)
def CezanneWindow(self,event):
wx.Panel(self)
title = "Paul Cezanne's Works"
keyID='Paul Cezanne'
frame = ArtFrame(parent=wx.GetTopLevelParent(self),title=title,keyID=keyID)
app = wx.App()
MainFrame(None)
app.MainLoop()
请注意,如果您发布了一小段代码,可以由任何人运行,而不需要您的数据库和jpg等,这将更容易
在
class ArtFrame(wx.Frame):
def __init__(self, keyID, title, parent):
wx.Frame.__init__(self,parent=parent,title=title,size=(800,600))
panel = wx.Panel(self)
wx.StaticText(panel,-1,"Working",(566,345))
self.SetBackgroundColour('white')
if keyID=='Auguste Renoir':
self.AugusteRenoirWork()
def AugusteRenoirWork(self):
UmbrellasButtonImage = wx.Image('The Umbrellas.jpg',wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
UmbrellasButton = wx.BitmapButton(wx.Panel(self),-1,UmbrellasButtonImage,pos=(200,200),size=(200,250))
当创建wx.BitmapButton时,它有一个新面板作为其父wx.Panel(self),而是使用在init中创建的面板
这样的事情
class ArtFrame(wx.Frame):
def __init__(self, keyID, title, parent):
wx.Frame.__init__(self,parent=parent,title=title,size=(800,600))
self.panel = wx.Panel(self)
wx.StaticText(self.panel,-1,"Working",(566,345))
self.SetBackgroundColour('white')
if keyID=='Auguste Renoir':
self.AugusteRenoirWork()
def AugusteRenoirWork(self):
UmbrellasButtonImage = wx.Image('The Umbrellas.jpg',wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
UmbrellasButton = wx.BitmapButton(self.panel,-1,UmbrellasButtonImage,pos=(200,200),size=(200,250))