import wx
class bucky(wx.Frame):
# Creating the outer window/frame
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Karls Network Tool', size=(900,700))
panel=wx.Panel(self, -1)
# Exit Button
button=wx.Button(panel,label="Exit",pos=(840,580),size=(40,40))
# Close event for exit button
self.Bind(wx.EVT_BUTTON, self.closebutton, button)
self.Bind(wx.EVT_CLOSE, self.closewindow)
# Network Topology Area - User can map a network
wx.TextCtrl(panel, -1, pos=(10,40), size=(525, 400)) # Network topology Panel
# Creating the bitmap buttons - Images appear on buttons
buttonOneRouter=wx.Image("router.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap()
self.buttonRouter=wx.BitmapButton(panel, -1, buttonOneRouter, pos=(20,580))
好吧所以我让我的Frame工作,因为我希望设置我需要的大小,我也有我的退出按钮,按预期工作等等.....所以我们可以看到一般程序工作正常。现在我想要的就是让程序执行以下操作:
- 向前迈出一步,如果可能的话,我会希望能够将这个小图像拖到该区域内的TextCtrl中,以便用户可以创建他们的模拟网络。
我知道这应该是非常简单的,因为我必须真正做的是创建一个事件来分配给按钮,但我甚至没有开始。有什么指针吗?
答案 0 :(得分:2)
以下是我认为你应该做的事情:
编写 init 方法,该方法也将图像作为您将用于textctrl背景的参数。
在您的情况下,它将是:
def __init__(self,parent, id, image)
创建您自己的app类并在OnInit方法上创建图像对象:
def OnInit(self):
image=wx.Image('your_image.jpg',wx.BITMAP_TYPE_JPEG)
self.frame=bucky(image)
其余的过程和其他事情一样。
答案 1 :(得分:2)
我认为您应该仔细查看文档和演示(wxPython的额外download)。有一个使用图像 - >拖动图像示例(至少在Windows版本中)完全符合您的要求(您同时使用了拖放和位图)。