Python教程 - Tkinter 简单计算器示例

简单的加法计算器


完整代码

import tkinter

def btn_click():
    sum = int(e1.get()) * int(e2.get())
    l2.config(text=sum)

main = tkinter.Tk()
main.geometry('300x100')

e1 = tkinter.Entry(main)
e1.insert(0, '0')
e1.config(width=10)
e1.grid(row=0, column=0)

l1 = tkinter.Label(main, text='*')
l1.grid(row=0, column=1)

e2 = tkinter.Entry(main)
e2.insert(0, '0')
e2.config(width=10)
e2.grid(row=0, column=2)

b1 = tkinter.Button(main, text='=')
b1.config(width=5)
b1.config(command=btn_click)
b1.grid(row=0, column=3)

l2 = tkinter.Label(main, text='0')
l2.grid(row=0, column=4)

posted @ 2022-05-29 18:36  hgrun  阅读(155)  评论(0编辑  收藏  举报