如果-否则不能在Tkinter下工作,请解决这个问题:


from tkinter import *
import tkinter.messagebox as tmsg
root = Tk()

def myaccount():
Label(root, text="nnEnter Your Account Number : ").pack(anchor="nw")
global en
en = Entry(font=" helectiva 11")
en.pack(anchor="nw")
def detail():
if en=="91xxxxxxxx":
Label(text="Hello").pack()
b = Button(root, text="View my Account Details",borderwidth=10,command=detail)
b.pack(anchor="nw")
txt = StringVar()
txt.set("——Welcome To Banking System Application——")
txt1 = StringVar()
txt1.set("*****************************************************")
txt2 = StringVar()
txt2.set("nnChoose from the Options :")
txt3 = StringVar()
txt3.set("—————————————————————————————")

Label(root, textvariable = txt).pack()
Label(root, textvariable = txt1).pack()
Label(root, textvariable = txt2).pack()
Label(root, textvariable= txt3).pack()
Button(root, text="View My Account",borderwidth=10,command=myaccount).pack(anchor="nw",ipadx=32)
Button(root, text="New Account",borderwidth=10).pack(anchor="nw",ipadx=72)
Button(root, text="Make a Transactiom",borderwidth=10).pack(anchor="nw")
Button(root, text="Exit",borderwidth=10,command=quit).pack(anchor="nw",ipadx=170)
root.mainloop()

请帮我一下。detail函数中的if子句不起作用。我试着连续5个小时解决它,但找不到正确的原因。但如果你找到了原因,请给出答案,我会非常感谢那个人。

条目对象不能是字符串。相反,您必须在条目对象中获取文本:

if en.get() == '91xxxxxxxx'
Label(text="Hello").pack()

最终代码:

from tkinter import *
import tkinter.messagebox as tmsg
root = Tk()

def myaccount():
Label(root, text="nnEnter Your Account Number : ").pack(anchor="nw")
global en
en = Entry(font=" helectiva 11")
en.pack(anchor="nw")
def detail():
if en.get() == '91xxxxxxxx'
Label(text="Hello").pack()
b = Button(root, text="View my Account Details",borderwidth=10,command=detail)
b.pack(anchor="nw")
txt = StringVar()
txt.set("——Welcome To Banking System Application——")
txt1 = StringVar()
txt1.set("*****************************************************")
txt2 = StringVar()
txt2.set("nnChoose from the Options :")
txt3 = StringVar()
txt3.set("—————————————————————————————")

Label(root, textvariable = txt).pack()
Label(root, textvariable = txt1).pack()
Label(root, textvariable = txt2).pack()
Label(root, textvariable= txt3).pack()
Button(root, text="View My Account",borderwidth=10,command=myaccount).pack(anchor="nw",ipadx=32)
Button(root, text="New Account",borderwidth=10).pack(anchor="nw",ipadx=72)
Button(root, text="Make a Transactiom",borderwidth=10).pack(anchor="nw")
Button(root, text="Exit",borderwidth=10,command=quit).pack(anchor="nw",ipadx=170)
root.mainloop()

相关内容

  • 没有找到相关文章

最新更新