用python里的tkinter窗口写加减乘除运算

#直接放在.py文件里按F5运行,
from tkinter import *
root = Tk()
sv1=StringVar()
sv2=StringVar()
sv3=StringVar()
l1=Label(text=“四则运算”)
l1.grid(row=0,column=0,columnspan=2)
e1=Entry()
e1.grid(row=1,column=0)
e1.config(textvariable=sv1)
e2=Entry()
e2.grid(row=2,column=0)
e2.config(textvariable=sv2)
e3=Entry()
e3.grid(row=3,column=0)
e3.config(textvariable=sv3)
def h1():
str=int(sv1.get())+int(sv2.get())
sv3.set(str)
def h2():
str=int(sv1.get())-int(sv2.get())
sv3.set(str)
def h3():
str=int(sv1.get())*int(sv2.get())
sv3.set(str)
def h4():
if sv2.get()==‘0’:
sv3.set(‘non’)
else:
str=int(sv1.get())/int(sv2.get())
sv3.set(str)
bt1=Button(command=h1,text="+",width=5,height=2)
bt1.grid(row=1,column=1,columnspan=1,rowspan=2,sticky=‘e’)

bt2=Button(command=h2,text="-",width=5,height=2)
bt2.grid(row=1,column=2,columnspan=1,rowspan=2,sticky=‘e’)

bt3=Button(command=h3,text="*",width=5,height=2)
bt3.grid(row=3,column=1,columnspan=1,rowspan=2,sticky=‘e’)

bt4=Button(command=h4,text="/",width=5,height=2)
bt4.grid(row=3,column=2,columnspan=1,rowspan=2,sticky=‘e’)

root.mainloop()

你可能感兴趣的:(窗口设计,软件)