python中的tkinter求助
展开全部
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 23 15:16:24 2020
@author: Roy
"""
from tkinter import *
window = Tk()
window.title('乘法')
window.geometry('400x450')
def is_num(x):
try: # 如果能运行int(x)语句,返回True
int(x)
return True
except ValueError: # ValueError为Python的一种标准异常,表示"传入无效的参数"
return False
def on_click1():
in3.delete(0,END)
entry_content1 = in1.get()
entry_content2 = in2.get()
if is_num(entry_content1) ==True and is_num(entry_content2) ==True:
out = int(entry_content1) * int(entry_content2)
in3.insert('insert',out)
else:
out = '请重新输入数值!'
in3.insert('insert',out)
def on_click2():
in3.delete(0,END)
entry_content1 = IntVar
entry_content2 = IntVar
label = Label(window,text ='请输入数值:')
label.place(x=155,y=0,width = 100,height = 20)
in1 = Entry(window,show=None,textvariable= entry_content1,font = 'Times 15 bold')
in1.place(x=85,y=60,width = 75,height = 75)
in2 = Entry(window,show=None,textvariable= entry_content2,font = 'Times 15 bold')
in2.place(x=275,y=60,width = 75,height = 75)
in3 = Entry(window,show=None,font = 'Times 15 bold')
in3.place(x=70,y=270,width = 245,height = 165)
b_no = Button(window,text='乘法',width=7,height=3,command = on_click1)
b_no.place(x=85,y=170)
b_no = Button(window,text='清空',width=7,height=3,command = on_click2)
b_no.place(x=290,y=170)
window.mainloop()
注意缩进
"""
Created on Tue Jun 23 15:16:24 2020
@author: Roy
"""
from tkinter import *
window = Tk()
window.title('乘法')
window.geometry('400x450')
def is_num(x):
try: # 如果能运行int(x)语句,返回True
int(x)
return True
except ValueError: # ValueError为Python的一种标准异常,表示"传入无效的参数"
return False
def on_click1():
in3.delete(0,END)
entry_content1 = in1.get()
entry_content2 = in2.get()
if is_num(entry_content1) ==True and is_num(entry_content2) ==True:
out = int(entry_content1) * int(entry_content2)
in3.insert('insert',out)
else:
out = '请重新输入数值!'
in3.insert('insert',out)
def on_click2():
in3.delete(0,END)
entry_content1 = IntVar
entry_content2 = IntVar
label = Label(window,text ='请输入数值:')
label.place(x=155,y=0,width = 100,height = 20)
in1 = Entry(window,show=None,textvariable= entry_content1,font = 'Times 15 bold')
in1.place(x=85,y=60,width = 75,height = 75)
in2 = Entry(window,show=None,textvariable= entry_content2,font = 'Times 15 bold')
in2.place(x=275,y=60,width = 75,height = 75)
in3 = Entry(window,show=None,font = 'Times 15 bold')
in3.place(x=70,y=270,width = 245,height = 165)
b_no = Button(window,text='乘法',width=7,height=3,command = on_click1)
b_no.place(x=85,y=170)
b_no = Button(window,text='清空',width=7,height=3,command = on_click2)
b_no.place(x=290,y=170)
window.mainloop()
注意缩进
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询