Herbiekim

python 编写交互界面

---恢复内容开始---

新建一个窗口

常用的python GUI库——tkinter

import tkinter

top = tkinter.Tk(className=\'python window app\')

top.mainloop()

 

窗口按钮选择

 1 from tkinter import *
 2 import easygui
 3 import psutil
 4 root = Tk()
 5 root.title("浏览器之战")
 6 
 7 #GIRLS = ["Google","IE","Ferox","soudog"]
 8 v = IntVar()
 9 
10 cpu_percent = psutil.cpu_percent(interval=1)
11 cpu_info = "CPU使用率已达到:%i%%" % cpu_percent
12 
13 def callback():
14     easygui.msgbox(cpu_info,title=\'实际内容是CPU使用率\')
15 group = LabelFrame(root,text="最好的浏览器是?") #基于root制作一个框架
16 group.pack(padx=70)
17 
18 v.set(1)
19 language = [(\'Google\',1),
20             (\'IE\',2),
21             (\'360\',3),
22             (\'soudog\',4)]
23 
24 
25 for lang,num in language:
26     b = Radiobutton(group,text=lang,variable=v,value=num,indicatoron=False,padx=30,pady=3)
27     l = Label(group,textvariable=v) #将内容添加到框架中
28 
29     l.pack()
30     b.pack(anchor=W,fill=X)
31 
32 theButton=Button(root,text=\'就是这个了\',command=callback)
33 theButton.pack(pady=20)
34 
35 mainloop()

print

 

 

 

 

 

 

 

---恢复内容结束---

分类:

技术点:

相关文章: