【发布时间】:2014-08-24 19:34:11
【问题描述】:
我正在使用 Python 2.7 进行编码,并且我正在尝试根据用户从不同窗口的下拉菜单中选择的单选按钮来更改背景位图图像。在附加的代码中,Bitmap0 图像是默认的。通过选择“照片”菜单,然后选择“更改照片”菜单项,会出现一个单选框。我希望能够选择 Bitmap1 并将位图图像更改为 Bitmap1 图像。
我没有成功地尝试过 pubsub,而且我从来没有对 pubsub 模块如何适应 Python 充满信心。这难道不能通过以正确的方式访问正确的变量来实现吗?
我的简化代码如下:
import wx
IPaa0 = 0
bgphoto = "bitmap" + str(IPaa0) + ".bmp"
print bgphoto
_ID_Item0 = wx.NewId()
_ID_Item1 = wx.NewId()
_ID_Item2 = wx.NewId()
_ID_Item3 = wx.NewId()
_ID_Item4 = wx.NewId()
_ID_Item5 = wx.NewId()
class cPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
def TogFot(self, fotnum):
print "TogFot Entered"
class aFotoDir(wx.App):
def OnInit(self):
iMainFrame = cMainFrame("Top Frame", (0, 0), (1200, 900))
iMainFrame.Show()
self.SetTopWindow(iMainFrame)
return True
class cMainFrame(wx.Frame):
def __init__(self, title, pos, size):
wx.Frame.__init__(self, None, -1, title, pos, size)
iPanel = cPanel(self)
MenuBar = wx.MenuBar()
mFile = wx.Menu()
MenuBar.Append(mFile, "File")
mFoto = wx.Menu()
MenuBar.Append(mFoto, "Photo")
self.SetMenuBar(MenuBar)
MenuItem0 = wx.Menu()
mFile.Append(_ID_Item0, "Open")
MenuItem1 = wx.Menu()
mFile.Append(_ID_Item1, "Save")
MenuItem2 = wx.Menu()
mFile.Append(_ID_Item2, "Save As")
MenuItem3 = wx.Menu()
mFile.Append(_ID_Item3, "Close")
MenuItem4 = wx.Menu()
mFile.Append(_ID_Item4, "Exit")
MenuItem5 = wx.Menu()
mFoto.Append(_ID_Item5, "Change Photo")
self.Bind(wx.EVT_MENU, self.ClickChFoto, id = _ID_Item5)
img0 = wx.Image(bgphoto, wx.BITMAP_TYPE_ANY)
img1 = wx.StaticBitmap(iPanel, -1, wx.BitmapFromImage(img0))
def ClickChFoto(self, event):
iSecondFrame = cSecondFrame("Input", (50, 0), (400, 300))
iSecondFrame.Show()
return True
class cSecondFrame(cMainFrame):
def __init__(self, title, pos, size):
wx.Frame.__init__(self, None, -1, title, pos, size)
iSecondPanel = wx.Panel(self, -1)
iBut0 = wx.Button(iSecondPanel, -1, "OK", pos = ( 75, 200))
iBut1 = wx.Button(iSecondPanel, -1, "CANCEL", pos = (225, 200))
Plist = ["Bitmap0", "Bitmap1"]
self.iWid0 = wx.RadioBox(iSecondPanel, -1, "Photo Selection", (50, 50),
(200, 100), Plist, 1, wx.RA_SPECIFY_COLS)
self.Bind(wx.EVT_BUTTON, self.ClickOK, iBut0)
self.Bind(wx.EVT_BUTTON, self.ClickCANCEL, iBut1)
def ClickOK(self, event):
print "OK Clicked"
global IPaa0
IPaa0 = self.iWid0.GetSelection()
print IPaa0
global bgphoto
bgphoto = "bitmap" + str(IPaa0) + ".bmp"
print bgphoto
self.Close(True)
def ClickCANCEL(self, event):
print "CANCEL Clicked"
self.Close(True)
#-------------------------------------------------------------------------------
if __name__ == "__main__":
app = aFotoDir(False)
app.MainLoop()
图像文件只是标题为“Bitmap0”和“Bitmap1”的两个文件。我不知道上传图片的协议,每张都超过6MB,所以我没有上传。
我将不胜感激任何指导和指导。
【问题讨论】:
标签: python-2.7 bitmap wxpython