Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python tkinter-标签未显示在第二个屏幕上_Python 3.x_Tkinter - Fatal编程技术网

Python 3.x Python tkinter-标签未显示在第二个屏幕上

Python 3.x Python tkinter-标签未显示在第二个屏幕上,python-3.x,tkinter,Python 3.x,Tkinter,我创建了一个带有“是/否”问题的代码,如果是,我使用一个输入框询问有多少个。但当我问到多少问题时,标签没有显示出来,我不明白为什么 提前感谢,以下是代码: from tkinter import filedialog, messagebox, ttk, constants from tkinter import * root = Tk() root.focus_force() root.withdraw() root.call('wm', 'attributes', '.', '-topmos

我创建了一个带有“是/否”问题的代码,如果是,我使用一个输入框询问有多少个。但当我问到多少问题时,标签没有显示出来,我不明白为什么

提前感谢,以下是代码:

from tkinter import filedialog, messagebox, ttk, constants
from tkinter import *

root = Tk()
root.focus_force()
root.withdraw()
root.call('wm', 'attributes', '.', '-topmost', True)
yesnob = messagebox.askyesno('Test','Do you have a clue?')
if yesnob == True:
    root2 = Tk()
    root2.call('wm', 'attributes', '.', '-topmost', True)
    root2.wm_title('How many ?')
    nb_b = 0
    title_loop = Label(root2, textvariable = 'How many ?', height = 2, width = 15)
    title_loop.grid(row = 1, column = 0)
    entrybox = Entry(root2, textvariable = nb_b, width = 5)
    entrybox.grid(row = 2, column = 0)
    def get_data():
        global nb_b
        try:
            nb_b = int((entrybox.get()))
        except ValueError:
            no_int = messagebox.showerror('Error', 'You did not enter a number, try again!')
        root.destroy()
        root2.destroy()
    exit_but = Button(root2, text = 'OK', command = get_data, height = 3, width = 5)
    exit_but.grid(row = 3, column = 1)
    root2.mainloop()
else:
    root.destroy()
root.mainloop()
将“textvariable”更改为“text”对我很有效:

title_loop = Label(root2, text = 'How many ?', height = 2, width = 15)
将“textvariable”更改为“text”对我很有效:

title_loop = Label(root2, text = 'How many ?', height = 2, width = 15)

您使用
textvariable
参数创建了
标签。如果将其更改为
text
,则会显示标签:

title_loop = Label(root2, text= 'How many ?', height = 2, width = 15)

textvariable
可与
StringVar
组合使用,前提是您希望有一个可更改的文本。如果文本是静态的,请使用
text
参数。

您使用
textvariable
参数创建了
标签。如果将其更改为
text
,则会显示标签:

title_loop = Label(root2, text= 'How many ?', height = 2, width = 15)
textvariable
可与
StringVar
组合使用,前提是您希望有一个可更改的文本。如果文本是静态的,请使用
text
参数