我正在创建一个界面,我需要单击一个按钮打开一个新窗口。所以我创建了主窗口,创建了所有按钮,并在一个类下创建了新窗口。我不完全确定是否需要,但我也会包含该信息。对python很抱歉,如果它充满了错误。
如果有人也可以回答如何在打开另一个窗口时隐藏主菜单,那就太好了。干杯。
import wxversion
wxversion.select("2.8")
import wx
class App(wx.App):
def OnInit(self):
frame = window()
frame.Show()
self.SetTopWindow(frame)
return True
class window(wx.Frame):
title = "Main Menu"
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Window', size=(1000,700))
panel=wx.Panel(self, -1)
self.SetBackgroundColour(wx.Colour(100,100,100))
self.Centre()
self.Show()
status=self.CreateStatusBar()
menubar=wx.MenuBar()
filemenu=wx.Menu()
exitmenu = filemenu.Append(wx.NewId(),"Exit", "Exit Program")
menubar.Append(filemenu,"File")
self.Bind(wx.EVT_MENU, self.onExit, exitmenu)
self.SetMenuBar(menubar)
font1 = wx.Font(30, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Consolas')
Text1=wx.StaticText(panel, -1, "Rhythm Trainer", (10,15))
Text1.SetFont(font1)
Text1.SetForegroundColour('white')
self.Show(True)
btn1 = wx.Button(panel, label='Basic', pos=(100,200), size=(150, 50))
btn1.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, u'Consolas'))
btn1.Bind( wx.EVT_BUTTON, window2)
btn2 = wx.Button(panel, label='Advanced', pos=(100,270), size=(150, 50))
btn2.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, u'Consolas'))
btn3 = wx.Button(panel, label='Notations', pos=(100,340), size=(150, 50))
btn3.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, u'Consolas'))
btn4 = wx.Button(panel, label='Settings', pos=(100,410), size=(150, 50))
btn4.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, u'Consolas'))
btn5 = wx.Button(panel, label="Quit", pos=(820, 550), size=(150, 50))
btn5.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, u'Consolas'))
self.Bind(wx.EVT_BUTTON, self.OnClick, btn5)
def OnClick(self, event):
self.Close()
def OnQuitButton(self, event):
wx.Sleep(1)
self.Destroy()
def onExit(self, event):
self.Destroy()
def newwindow(self, event):
window2.show
class window2(wx.Frame):
title = "new Window"
def __init__(self,parent,id):
wx.Frame.__init__(self, id,'Window2', size=(1000,700))
panel=wx.Panel(self, -1)
self.SetBackgroundColour(wx.Colour(100,100,100))
self.Centre()
self.Show()
if __name__=='__main__':
app=wx.PySimpleApp()
frame=window(parent=None,id=-1)
frame.Show()
app.MainLoop()