窗口上创建菜单,子菜单实现退出
将现有数据库输出部署到左边区域
菜单退出就是要绑定事件,
数据显示, 可以考虑用多行文本
大概界面的写法如下,供参考
# encoding: utf-8
"""
@author: 陈年椰子
@contact: hndm@qq.com
@version: 1.0
@project:test
@file: wx_gui7.py
@time: 2022-3-9 9:36
说明
"""
import wx
class MainWindow(wx.Frame):
def __init__(self, parent, title, size=(400,200)):
wx.Frame.__init__(self, parent=parent, title=title, size=size)
self.Center() # 设置窗口居中
# 放一个面板,用于布局其他控件
panel = wx.Panel(parent=self)
# 定义相关控件
# btn1 = wx.Button(panel, label="左")
btn2 = wx.Button(panel, label="右1")
btn3 = wx.Button(panel, label="右2 自动扩展")
text1 = wx.TextCtrl(panel, size=(300,100),
style=wx.TE_MULTILINE)
text2 = wx.TextCtrl(panel)
text3 = wx.TextCtrl(panel)
text3.SetValue("自动扩展")
text1.SetValue(str)
# 创建右边子区域
vbox_right_1 = wx.BoxSizer(wx.VERTICAL)
vbox_right_2 = wx.BoxSizer(wx.VERTICAL)
# 右边子区域增加控件
vbox_right_1.Add(text2, proportion=0, flag=wx.ALL, border=10)
vbox_right_1.Add(btn2, proportion=0, flag=wx.ALL, border=10)
vbox_right_2.Add(text3, proportion=1, flag=wx.ALL| wx.EXPAND, border=10)
vbox_right_2.Add(btn3, proportion=1, flag=wx.ALL| wx.EXPAND, border=10)
# 创建右grid,垂直缝隙,水平缝隙
gridsizer_right = wx.GridSizer(cols=1, rows=2, vgap=10, hgap=5)
gridsizer_right.AddMany([(vbox_right_1, 1,wx.ALL | wx.EXPAND), (vbox_right_2, 1, wx.ALL | wx.EXPAND)])
# 创建区域
vbox1 = wx.BoxSizer(wx.VERTICAL)
# 左边区域增加控件
vbox1.Add(text1, proportion=1, flag=wx.ALL, border=10)
# vbox1.Add(btn1, proportion=0, flag=wx.ALL, border=10)
vbox2 = wx.BoxSizer(wx.VERTICAL)
vbox2.Add(gridsizer_right, proportion=1, flag=wx.ALL | wx.EXPAND, border=15)
# 创建主grid,垂直缝隙,水平缝隙
gridsizer = wx.GridSizer(cols=2, rows=1, vgap=10, hgap=5)
gridsizer.AddMany([(vbox1, 1, wx.EXPAND), (vbox2, 1, wx.ALL | wx.EXPAND) ])
panel.SetSizer(gridsizer)
# 菜单栏
file_menu = wx.Menu()
file_menu.Append(wx.ID_SAVE, '保存', '将会保存内容')
gexit = file_menu.Append(wx.ID_EXIT, '退出', '退出')
window_menu = wx.MenuBar()
window_menu.Append(file_menu, '文件')
self.SetMenuBar(window_menu)
self.Bind(wx.EVT_MENU,self.GuiExit,gexit)
# 创建状态栏
self.statusbar = self.CreateStatusBar()
self.statusbar.SetFieldsCount(3)
self.statusbar.SetStatusWidths([-1, -2, -3])
self.statusbar.SetStatusText(u"数据1" , 0)
self.statusbar.SetStatusText(u"数据2:" , 1)
self.statusbar.SetStatusText(u"数据3:" , 2)
self.Show(True)
def GuiExit(self,e):
self.Close()
# 这里替换掉你的数据
str = "122\n1231312\ndsjfsdf"
app = wx.App()
window = MainWindow(None, '测试')
app.MainLoop()