怎么回事,求帮助,就是我在编写一个计算器,tkinter遇到错误
一般是前一行少了一个括号)
, 在前一行的末尾添加一个括号)
即可。
若有帮助, 点一个"采纳"不谢。
from tkinter import *
def Mysel():
dic = {0: 0, 1: 1, 2: 2, 3: 3}
texd = dic.get(var.get())
return (texd)
h=0
def ko():
global h
def ok(mk, num11, num22, h):
if (mk == "+"):
h = num11 + num22
if (mk == "-"):
h = num11 - num22
if (mk == "x"):
h = num11 * num22
if (mk == "/"):
h = num11 / num22
return (h)
texd = Mysel()
if (texd == 0):
root.destroy()
root1 = Tk()
root1.geometry('300x300')
root1.title("加法运算")
num1 = Entry(root1, bd=5, width=50)
num1.place(x=100, y=50)
qwe = Label(root1, text="+")
qwe.place(x=150, y=50)
num2 = Entry(root1, bd=5, width=50)
num2.place(x=200, y=50)
ok1 = Button(root1, text="ok", bg="white", command=lambda: ok("+", num1.get(), num2.get(), h))
ok1.place(x=125, y=100)
mio = Label(root1, text=h)
mio.place(x=150, y=150)
root1.mainloop()
if (texd == 1):
root.destroy()
root1 = Tk()
root1.geometry('300x300')
root1.title("减法运算")
num1 = Entry(root1, bd=5, width=50)
num1.place(x=100, y=50)
qwe = Label(root1, text="-")
qwe.place(x=150, y=50)
num2 = Entry(root1, bd=5, width=50)
num2.place(x=200, y=50)
ok1 = Button(root1, text="ok", bg="white", command=lambda: ok("-", num1.get(), num2.get(), h))
ok1.place(x=125, rely=100)
mio = Label(root1, text=h)
mio.place(x=150, y=150)
root1.mainloop()
if (texd == 2):
root.destroy()
root1 = Tk()
root1.geometry('300x300')
root1.title("乘法运算")
num1 = Entry(root1, bd=5, width=50)
num1.place(x=100, y=50)
qwe = Label(root1, text="×")
qwe.place(x=150, y=50)
num2 = Entry(root1, bd=5, width=50)
num2.place(x=200, y=50)
ok1 = Button(root1, text="ok", bg="white", command=lambda: ok("x", num1.get(), num2.get(), h))
ok1.place(x=125, y=100)
# xxxxxxxxxxxx>
mio = Label(root1, text=h)
mio.place(x=150, y=150)
root1.mainloop()
if (texd == 3):
root.destroy()
root1 = Tk()
root1.geometry('300x300')
root1.title("除法运算")
num1 = Entry(root1, bd=5, width=50)
num1.place(x=100, y=50)
qwe = Label(root1, text="÷")
qwe.place(x=150, y=50)
num2 = Entry(root1, bd=5, width=50)
num2.place(x=200, y=50)
ok1 = Button(root1, text="ok", bg="white", command=lambda: ok("/", num1.get(), num2.get(), h))
ok1.place(x=125, y=100)
mio = Label(root1, text=h)
mio.place(x=150, y=150)
root1.mainloop()
root = Tk()
root.title('计算器')
var = IntVar()
rd1 = Radiobutton(root, text="+", variable=var, value=0, command=Mysel)
rd1.pack()
rd2 = Radiobutton(root, text="-", variable=var, value=1, command=Mysel)
rd2.pack()
rd3 = Radiobutton(root, text="x", variable=var, value=2, command=Mysel)
rd3.pack()
rd3 = Radiobutton(root, text="/", variable=var, value=3, command=Mysel)
rd3.pack()
ok = Button(root, text="ok", bg="white", command=ko)
ok.pack()
root.mainloop()
建议你看下这篇博客Tkinter使用教程(一)