import tkinter |
guo = tkinter.Tk() |
guo.title( "计算求和" ) |
guo.geometry( "370x300" ) |
v = tkinter.IntVar() |
lab1 = tkinter.Label(guo, text = "求和数A:" ) |
lab1.grid(row = 0 , column = 0 ) |
entl = tkinter.Entry(guo, textvariable = v, width = 20 ) |
entl.grid(row = 1 , column = 0 ) |
scl = tkinter.Scale(guo, label = "数Ad取值范围-1000至1000" , from_ = - 1000 , to = 1000 , resolution = 1 , |
digits = 0 , orient = tkinter.HORIZONTAL, variable = v, length = 180 ) |
scl.grid(row = 2 , column = 0 ) |
s = tkinter.IntVar() |
lab2 = tkinter.Label(guo, text = "求和数B:" ) |
lab2.grid(row = 0 , column = 1 ) |
ent2 = tkinter.Entry(guo, textvariable = s, width = 20 ) |
ent2.grid(row = 1 , column = 1 ) |
sc2 = tkinter.Scale(guo, label = "数B的取值范围-1000至1000" , from_ = - 1000 , to = 1000 , resolution = 1 , |
digits = 0 , orient = tkinter.HORIZONTAL, variable = s, length = 180 ) |
sc2.grid(row = 2 , column = 1 ) |
def pa(): |
p = scl.get() + sc2.get() |
b1.config(text = "求和的结果为:" + str (p), state = tkinter.DISABLED) |
def pb(): |
scl. set ( 0 ) |
sc2. set ( 0 ) |
b1.config(text = "求和" , state = tkinter.NORMAL) |
b1 = tkinter.Button(guo, text = "求和" , width = 20 , command = pa) |
b1.grid(row = 3 , column = 0 , pady = 5 ) |
b2 = tkinter.Button(guo, text = "清空" , width = 20 , command = pb) |
b2.grid(row = 3 , column = 1 ) |
guo.mainloop() |
#q:1752272569 |
中级程序员
by: 小guo 发表于:2023-06-01 21:33:53 顶(3) | 踩(0) 回复
回复评论