Home  >  Article  >  Backend Development  >  How to write interactive interface in Python?

How to write interactive interface in Python?

Guanhui
GuanhuiOriginal
2020-06-23 15:00:179482browse

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

How to write interactive interface in Python?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn