我想要创建一个图形用户界面在Windows我的Python程序,我有点糊涂了ATM ..我应该如何在我的应用程序中使用wxFormBuilder Python GUI代码?
我已经创建使用wxFormBuilder GUI和它看起来像这样:
# -*- coding: utf-8 -*-
###########################################################################
## Python code generated with wxFormBuilder (version Jun 17 2015)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################
import wx
import wx.xrc
###########################################################################
## Class MainFrame
###########################################################################
class MainFrame (wx.Frame):
def __init__(self, parent):
wx.Frame.__init__ (self, parent, id = wx.ID_ANY, title = u"Editor_SPED_LP", pos = wx.DefaultPosition, size = wx.Size(320,255), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL)
self.SetSizeHintsSz(wx.Size(320,255), wx.Size(320,255))
bSizer1 = wx.BoxSizer(wx.VERTICAL)
self.m_textCtrl2 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
bSizer1.Add(self.m_textCtrl2, 0, wx.ALL|wx.EXPAND, 5)
self.m_btn_abrirArq = wx.Button(self, wx.ID_ANY, u"Abrir arquivo...", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer1.Add(self.m_btn_abrirArq, 0, wx.ALL, 5)
self.m_btn_editarTxt = wx.Button(self, wx.ID_ANY, u"Editar .txt", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer1.Add(self.m_btn_editarTxt, 0, wx.ALL, 5)
self.m_gauge1 = wx.Gauge(self, wx.ID_ANY, 100, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL)
self.m_gauge1.SetValue(0)
bSizer1.Add(self.m_gauge1, 0, wx.ALL, 5)
self.m_btn_ajuda = wx.Button(self, wx.ID_ANY, u"Ajuda", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer1.Add(self.m_btn_ajuda, 0, wx.ALL, 5)
self.m_staticText2 = wx.StaticText(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText2.Wrap(-1)
bSizer1.Add(self.m_staticText2, 0, wx.ALL, 5)
self.m_btn_sair = wx.Button(self, wx.ID_ANY, u"Sair", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer1.Add(self.m_btn_sair, 0, wx.ALL, 5)
self.SetSizer(bSizer1)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.m_btn_abrirArq.Bind(wx.EVT_BUTTON, self.abrirArquivo)
self.m_btn_editarTxt.Bind(wx.EVT_BUTTON, self.editarTxt)
self.m_btn_ajuda.Bind(wx.EVT_BUTTON, self.janelaAjuda)
self.m_btn_sair.Bind(wx.EVT_BUTTON, self.sair)
def __del__(self):
pass
# Virtual event handlers, overide them in your derived class
def abrirArquivo(self, event):
event.Skip()
def editarTxt(self, event):
event.Skip()
def janelaAjuda(self, event):
event.Skip()
def sair(self, event):
event.Skip()
当我从终端运行它不显示任何错误......
how am i supposed to use it with my application?
我找到这个教程here,但我无法理解它..
还我试图在脚本的末尾添加代码:
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
frame.Show()
app.MainLoop()
,并得到这个错误:
File "gui.py", line 80, in <module>
frame = MainFrame(seld,parent)
NameError: name 'self' is not defined
所以..它看起来像GUI代码是好的,问题是我不知道如何初始化它并添加一些功能。
有人可以帮我解决这个问题吗?
在哪里截图? –
图片在:http://i.stack.imgur.com/F3jhO.png –
现在显示。它只是一个长方形的白色盒子 –