参考:https://www.cnblogs.com/morries123/p/8568666.html
图形化编写:
class MyFrame(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self, parent, id=-1, title="Jira bug统计工具", size=(410, 335))
bkg = wx.Panel(self)
wx.StaticText(bkg, id=-1, label='用户名', pos=(50, 30), size=wx.DefaultSize, style=0, name="staticText")
wx.StaticText(bkg, id=-1, label='密码', pos=(220, 30), size=wx.DefaultSize, style=0, name="staticText")
wx.StaticText(bkg, id=-1, label='项目名称', pos=(30, 150), size=wx.DefaultSize, style=0, name="staticText")
wx.StaticText(bkg, id=-1, label='测试轮次', pos=(30, 190), size=wx.DefaultSize, style=0, name="staticText")
execButton = wx.Button(parent = bkg, id=-1, label='执行', pos=(300, 160))
self.username = wx.TextCtrl(bkg, id=-1, pos=(40, 50), size=(150, -1), name='TC01') # 用户名输入框
self.password = wx.TextCtrl(bkg, id=-1, pos=(200, 50), size=(150, -1), style = wx.TE_PASSWORD) # 密码输入框
projectList = ['项目1', '项目2', '项目3', '项目4']
self.projectname = wx.ComboBox(bkg, pos=(85, 150), size=(185, -1), choices=projectList) # 项目名称下拉框
timeList = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15']
self.times = wx.ComboBox(bkg, id=-1, pos=(85, 190), size=(185, -1), choices=timeList) # 测试轮次下拉框
事件绑定:
1.定义事件函数
def Exec(self,evt):
username = self.username.GetValue()
password = self.password.GetValue()
projectname = self.projectname.GetValue()
times = self.times.GetValue()
with open('txt.txt','w+') as f:
f.write('username={},password={},projectname={},times={}'.format(username, password, projectname, times))
2.绑定触发事件的条件
self.Bind(wx.EVT_BUTTON, self.Exec, execButton)
完整代码:
import wx
class MyFrame(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self, parent, id=-1, title="Jira bug统计工具", size=(410, 335))
bkg = wx.Panel(self)
wx.StaticText(bkg, id=-1, label='用户名', pos=(50, 30), size=wx.DefaultSize, style=0, name="staticText")
wx.StaticText(bkg, id=-1, label='密码', pos=(220, 30), size=wx.DefaultSize, style=0, name="staticText")
wx.StaticText(bkg, id=-1, label='项目名称', pos=(30, 150), size=wx.DefaultSize, style=0, name="staticText")
wx.StaticText(bkg, id=-1, label='测试轮次', pos=(30, 190), size=wx.DefaultSize, style=0, name="staticText")
execButton = wx.Button(parent = bkg, id=-1, label='执行', pos=(300, 160))
self.username = wx.TextCtrl(bkg, id=-1, pos=(40, 50), size=(150, -1), name='TC01') # 用户名输入框
self.password = wx.TextCtrl(bkg, id=-1, pos=(200, 50), size=(150, -1), style = wx.TE_PASSWORD) # 密码输入框
projectList = ['项目1', '项目2', '项目3', '项目4']
self.projectname = wx.ComboBox(bkg, pos=(85, 150), size=(185, -1), choices=projectList) # 项目名称下拉框
timeList = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15']
self.times = wx.ComboBox(bkg, id=-1, pos=(85, 190), size=(185, -1), choices=timeList) # 测试轮次下拉框
self.Bind(wx.EVT_BUTTON, self.Exec, execButton)
def Exec(self,evt):
username = self.username.GetValue()
password = self.password.GetValue()
projectname = self.projectname.GetValue()
times = self.times.GetValue()
with open('txt.txt','w+') as f:
f.write('username={},password={},projectname={},times={}'.format(username, password, projectname, times))
class MyApp(wx.App):
def OnInit(self):
self.frame=MyFrame(parent=None)
self.SetTopWindow(self.frame)
self.frame.Show(True)
return True
if __name__ == '__main__':
app = MyApp()
app.MainLoop()