编程语言
首页 > 编程语言> > python gui

python gui

作者:互联网

运行截图:


代码:

# encoding:utf-8
import tkinter as tk

root = tk.Tk()
root.title("Small Calculator")
root.geometry('500x300')

var1 = tk.DoubleVar()
label1 = tk.Label(text="第一个数字", width=20, height=2)
label1.pack()
entry1 = tk.Entry(width=20)
entry1.pack()

var2 = tk.StringVar()
label2 = tk.Label(text="符号", width=20, height=2)
label2.pack()
entry2 = tk.Entry(width=20)
entry2.pack()

var3 = tk.DoubleVar()
label3 = tk.Label(text="第二个数字", width=20, height=2)
label3.pack()
entry3 = tk.Entry(width=20)
entry3.pack()

var4 = tk.DoubleVar()
label4 = tk.Label(text="结果", width=20, height=2)
label4.pack()
label5 = tk.Label(textvar=var4, width=30, height=1,)
label5.pack()

def clickFun():
    global var1
    global var2
    global var3
    global var4
    va11 = int(entry1.get())
    var2 = entry2.get()
    var3 = int(entry3.get())
    if var2 == '+':
        var4.set(int(va11+var3))
    elif var2 == '-':
        var4.set(int(va11-var3))
    elif var2 == '':
        var4.set(int(va11*var3))
    elif var2 == '/':
        if var3 == 0:
            var4.set("请重新输入数据")
        else:
            var4.set(int(va11/var3))
    else:
        var4.set("运算符出错,请重新输入数据")

button1 = tk.Button(text="完成" ,width=10, height=2, command=clickFun)
button1.pack()
root.mainloop()

标签:var4,20,var3,python,gui,width,tk,pack
来源: https://www.cnblogs.com/fanchaoming/p/15675825.html