Home > Article > Backend Development > How to write interactive interface in Python?
How to write an interactive interface in Python?
First import the Python GUI library tkinter; then use the tkinter interface "Tk" to create the interface; then use the interface "title" to set the interface title, and "geometry" to set the interface size; finally call "mainloop" that is Can.
Sample code
from tkinter import * import easygui import psutil root = Tk() root.title("浏览器之战") #GIRLS = ["Google","IE","Ferox","soudog"] v = IntVar() cpu_percent = psutil.cpu_percent(interval=1) cpu_info = "CPU使用率已达到:%i%%" % cpu_percent def callback(): easygui.msgbox(cpu_info,title='实际内容是CPU使用率') group = LabelFrame(root,text="最好的浏览器是?") #基于root制作一个框架 group.pack(padx=70) v.set(1) language = [('Google',1), ('IE',2), ('360',3), ('soudog',4)] for lang,num in language: b = Radiobutton(group,text=lang,variable=v,value=num,indicatoron=False,padx=30,pady=3) l = Label(group,textvariable=v) #将内容添加到框架中 l.pack() b.pack(anchor=W,fill=X) theButton=Button(root,text='就是这个了',command=callback) theButton.pack(pady=20) mainloop()
Rendering
Recommended tutorial: "Python Tutorial"
The above is the detailed content of How to write interactive interface in Python?. For more information, please follow other related articles on the PHP Chinese website!