-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
121 lines (96 loc) · 3.63 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
import Tkinter
import tkFileDialog
import spice
class MainFrame(Tkinter.Frame):
def __init__(self, master=None):
Tkinter.Frame.__init__(self, master)
self.grid(row=0, column=0, sticky="nsew")
self.createFrame()
def createFrame(self):
label_frame_top = Tkinter.LabelFrame(self)
# label_frame_top.pack()
label_frame_center = Tkinter.LabelFrame(self)
label_frame_center.pack(fill="x")
lfc_field_1 = Tkinter.LabelFrame(label_frame_center)
lfc_field_1.pack(fill="x")
self.lfc_field_1_l = Tkinter.Button(
lfc_field_1, text="open file", width=10, command=self.openFile)
self.lfc_field_1_l.pack(fill="none", expand=0, side=Tkinter.LEFT)
self.lfc_field_1_b = Tkinter.Button(
lfc_field_1,
text="clear",
width=10,
height=1,
command=self.clearText)
self.lfc_field_1_b.pack(
fill="none",
expand=0,
side=Tkinter.RIGHT,
anchor=Tkinter.SE)
self.lfc_field_1_b = Tkinter.Button(
lfc_field_1, text="run", width=10, height=1, command=self.var)
self.lfc_field_1_b.pack(
fill="none",
expand=0,
side=Tkinter.RIGHT,
anchor=Tkinter.SE)
# 文本框与滚动条
self.lfc_field_1_t_sv = Tkinter.Scrollbar(
lfc_field_1, orient=Tkinter.VERTICAL) # 文本框-竖向滚动条
self.lfc_field_1_t_sh = Tkinter.Scrollbar(
lfc_field_1, orient=Tkinter.HORIZONTAL) # 文本框-横向滚动条
self.lfc_field_1_t = Tkinter.Text(
lfc_field_1,
height=15,
yscrollcommand=self.lfc_field_1_t_sv.set,
xscrollcommand=self.lfc_field_1_t_sh.set,
wrap='none') # 设置滚动条-不换行
# 滚动事件
self.lfc_field_1_t_sv.config(command=self.lfc_field_1_t.yview)
self.lfc_field_1_t_sh.config(command=self.lfc_field_1_t.xview)
# 布局
self.lfc_field_1_t_sv.pack(
fill="y",
expand=0,
side=Tkinter.RIGHT,
anchor=Tkinter.N)
self.lfc_field_1_t_sh.pack(
fill="x",
expand=0,
side=Tkinter.BOTTOM,
anchor=Tkinter.N)
self.lfc_field_1_t.pack(fill="x", expand=1, side=Tkinter.LEFT)
# 绑定事件
self.lfc_field_1_t.bind("<Control-Key-a>", self.selectText)
self.lfc_field_1_t.bind("<Control-Key-A>", self.selectText)
# 文本框与滚动条end
label_frame_bottom = Tkinter.LabelFrame(self)
# label_frame_bottom.pack()
pass
# 文本全选
def selectText(self, event):
self.lfc_field_1_t.tag_add(Tkinter.SEL, "1.0", Tkinter.END)
#self.lfc_field_1_t.mark_set(Tkinter.INSERT, "1.0")
# self.lfc_field_1_t.see(Tkinter.INSERT)
return 'break' # 为什么要return 'break'
# 文本清空
def clearText(self):
self.lfc_field_1_t.delete(0.0, Tkinter.END)
def openFile(self):
self.filename = tkFileDialog.askopenfilename(initialdir='./')
self.f = open(self.filename)
for line in self.f.readlines():
self.lfc_field_1_t.insert(Tkinter.END, line)
def var(self):
spice.main(self.filename)
def main():
root = Tkinter.Tk()
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
root.geometry('640x360') # 设置了主窗口的初始大小960x540 800x450 640x360
main_frame = MainFrame(root)
main_frame.mainloop()
if __name__ == "__main__":
main()
pass