Python tkinter错误标签不';不出现

Python tkinter错误标签不';不出现,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我和特金特之间一直有问题。 它应该是第一个windows文本框上的号码 检查它是否可以被5整除,如果可以,将它除以5并将其置于弹出窗口中。如果不是,就把数字放在弹出窗口上,不要除以5 代码如下: from tkinter import * from tkinter import ttk import tkinter as tk answer = 0 def popup(): global answer if (number[-1] == 5 or number[-1] == 0)

我和特金特之间一直有问题。 它应该是第一个windows文本框上的号码 检查它是否可以被5整除,如果可以,将它除以5并将其置于弹出窗口中。如果不是,就把数字放在弹出窗口上,不要除以5

代码如下:

from tkinter import *
from tkinter import ttk
import tkinter as tk
answer = 0
def popup():
    global answer
    if (number[-1] == 5 or number[-1] == 0):
        number / 5
        if (int(number) > 1):
            answer = "\number 5 cent coins"
        else:
            answer = "\number 5 cent coin"
    else:
        if (int(number) > 1):
            answer = "\number 1 cent coins"
        else:
            answer = "\number 1 cent coin"
    popup = tk.Tk()
    popup.wm_title("answer")
    popup.geometry("330x85")
    answers = Label(popup, text=answer)
    answers.pack
    B1 = ttk.Button(popup, text="Ok", command=popup.destroy)
    B1.pack()
def add_text():
    global number
    number = num_textbox.get()
    print(number)
    popup()
    root.destroy()
root = Tk()
root.title("Number Cent Divider")
root.geometry("330x85")
num_col_mat = Label(root, text="Your number:")
num_col_mat.pack()
num_textbox = Entry(root, bd=1)
num_textbox.pack()
enter_button = Button(root, text="Enter", command=add_text)
enter_button.pack()
root.mainloop()
并且不会出现错误,但弹出窗口上的标签不会出现在:

popup = tk.Tk()
popup.wm_title("answer")
popup.geometry("330x85")
answers = Label(popup, text=answer)
answers.pack
B1 = ttk.Button(popup, text="Ok", command=popup.destroy)
B1.pack()

您需要在标签对象上调用
pack
,即在
pack
之后添加
()


因此,您打包
答案的地方应该是
答案。pack()

您需要在标签对象上调用
pack
,即在
pack
之后添加
()


因此,打包
answers
的地方应该是
answers.pack()

不要创建多个Tk()实例。改为用作您的
弹出窗口
@Lafexlos我尝试使用Toplevel(),但它给了我一个错误,说Toplevel()未定义编辑:不管怎样,它成功了。但是有什么区别呢?不要创建多个Tk()实例。改为用作您的
弹出窗口
@Lafexlos我尝试使用Toplevel(),但它给了我一个错误,说Toplevel()未定义编辑:不管怎样,它成功了。但是有什么区别?