Created
March 2, 2018 03:33
-
-
Save PandyYang/93690c963559b10ea5049ee8c1f3905c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import * | |
master = Tk() | |
frame = Frame(master) | |
frame.pack(padx = 10,pady =10) | |
v1= StringVar() | |
v2 = StringVar() | |
v3 = StringVar() | |
def test(content): | |
return content.isdigit() | |
testCMD = frame.register(test) | |
e1 = Entry(frame,textvariable=v1,validate = "key",\ | |
validatecommand = (testCMD,"%P")).grid(row = 0,\ | |
column = 0) | |
Label(frame,text = "+").grid(row = 0,column = 1) | |
e2 = Entry(frame,textvariable=v2,validate = "focusout",\ | |
validatecommand = (testCMD,"%P")).grid(row = 0,\ | |
column = 2) | |
Label(frame,text = "=").grid(row = 0,column = 3) | |
e3 = Entry(frame,textvariable = v3,state = "readonly").grid(row = 0,\ | |
column = 4) | |
def calc(): | |
result = int(v1.get())+ int(v2.get()) | |
v3.set(str(result)) | |
Button(frame,text = "计算结果",command = calc).grid(row = 1,column = 2,pady = 5) | |
mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment