-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
47 lines (32 loc) · 1.24 KB
/
GUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# #!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
def OnOpen(event) :
dialog = wx.FileDialog(None,'items',style = wx.OPEN)
if dialog.ShowModal() == wx.ID_OK :
filename.SetValue(dialog.GetPath())
file = open(dialog.GetPath())
contents.SetValue(file.read().decode('utf-8','ignore').encode('gbk'))
file.close()
dialog.Destroy()
app = wx.App()
win = wx.Frame(None,title = "lvxubo's notepad",size = (410,335))
bkg = wx.Panel(win)
# 创建组件
openbutton = wx.Button(bkg,label = 'Open')
openbutton.Bind(wx.EVT_BUTTON,OnOpen)
savebutton = wx.Button(bkg,label = 'Save')
filename = wx.TextCtrl(bkg)
contents = wx.TextCtrl(bkg,style = wx.TE_MULTILINE|wx.HSCROLL)
# 生成布局管理器 使组件随着鼠标更改
hbox = wx.BoxSizer()
hbox.Add(filename,proportion = 1,flag = wx.EXPAND)
hbox.Add(openbutton,proportion = 0,flag = wx.LEFT,border = 5)
hbox.Add(savebutton,proportion = 0,flag = wx.LEFT,border = 5)
# 一个布局管理器可以包含另一个管理器
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(hbox,proportion = 0,flag = wx.EXPAND|wx.ALL,border = 5)
vbox.Add(contents,proportion = 1,flag = wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM,border = 5)
bkg.SetSizer(vbox)
win.Show()
app.MainLoop()