Блокнот программы Python Gui можно ввести

Блокнот программы Python gui можно ввести и имеет раскрывающуюся панель

вставьте сюда описание изображения
Непосредственно загрузите исходный код ниже

import wx

class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(None,-1,title="记事本",size=(400,400))
        panel=wx.Panel(parent=self)#创建文本
        self.text=wx.TextCtrl(panel,size=(300,200),pos=(50,30),style=wx.TE_MULTILINE)
        self.btn_clear=wx.Button(panel,pos=(180,250),label="清空",size=(80,30))
        self.Bind(wx.EVT_BUTTON,self.OnClear,self.btn_clear)



        caidan=wx.Menu()#设置菜单
        item1=caidan.Append(wx.ID_ABOUT,"关于")#标准ID ID.ABOUT
        #caidan.AppendSeparator()#分隔符

        item2=caidan.Append(wx.ID_EXIT,"退出")#标准ID ID.EXIT
        item3=caidan.Append(wx.ID_HELP,"help")


        editmenu=wx.Menu()
        item21=editmenu.Append(wx.ID_OPEN,"打开")
        item11=editmenu.Append(wx.ID_SAVE,"保存")


        caidan2=wx.Menu()
        item22=caidan2.Append(wx.ID_ABORT,"1")
        item33=caidan2.Append(wx.ID_ADD,"2")


        caidan3=wx.Menu()
        item44=caidan3.Append(wx.ID_ANY,"1")
        item55 =caidan3.Append(wx.ID_ABOUT, "2")


        caidan4=wx.Menu()
        item66=caidan4.Append(wx.ID_HELP,"1")


        #创建菜单栏
        menuBar=wx.MenuBar()
        menuBar.Append(caidan,"文件(F)")
        menuBar.Append(editmenu,"编辑(E)")
        menuBar.Append(caidan2,"格式(O)")
        menuBar.Append(caidan3, "查看(V)")
        menuBar.Append(caidan4, "帮助(H)")

        self.SetMenuBar(menuBar)

        self.Bind(wx.EVT_MENU,self.OnQuit,item2)
        self.Bind(wx.EVT_MENU,self.OnAbout,item1)
        self.Bind(wx.EVT_MENU,self.OnOpen,item21)

    def OnQuit(self,e):
        self.Close()

    def OnAbout(self,e):
        dlg=wx.MessageDialog(self,"请充值后再使用","温馨提示")
        dlg.ShowModal()
        dlg.Destroy()

    def OnOpen(self,e):
        file=open("AAAAA1.txt","r")
        content=file.read()
        self.text.SetValue(content)

    def OnClear(self,e):
        self.text.SetValue("")


class MyApp(wx.App):
    def OnInit(self):
        frame=MyFrame()
        frame.Show()
        return True

if __name__=="__main__":
    app=MyApp()
    app.MainLoop()```

Guess you like

Origin blog.csdn.net/qq_49623539/article/details/127830872