我是wxPython的新手。我创建了一个包含按钮的简单GUI,按下该按钮我正在调用另一个.py文件......但是我使用命令收到错误:
top_block.start()
错误是:
AttributeError:'module'对象没有属性'start'
代码如图所示。我使用的是python 2.7.3。欢迎使用代码中的任何改进。
import wx
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, title="The Main Frame")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
class MyFrame(wx.Frame):
def __init__(self, parent, id=wx.ID_ANY, title="",
pos=wx.DefaultPosition, size=wx.DefaultSize,
style=wx.DEFAULT_FRAME_STYLE,
name="MyFrame"):
super(MyFrame, self).__init__(parent, id, title,
pos, size, style, name)
# Attributes
self.panel = wx.Panel(self)
self.panel.SetBackgroundColour(wx.BLACK)
self.button3=wx.Button(self, -1, ' Execute ', wx.Point(235, 90),
wx.DefaultSize)
self.Bind(wx.EVT_BUTTON, self.Execute,self.button3)
def Execute(self,event):
import top_block
top_block.start()
if __name__ == "__main__":
app = MyApp(False)
app.MainLoop()
答案 0 :(得分:0)
如果start
中有top_block
方法,则它必须是顶级方法,否则如果top_block.py
中有一个名为top_block
的类具有方法您首先需要top_block.top_block.start()
或将导入更改为from top_block import top_block
,以便引用该对象的方法。