简体   繁体   English

Python tkinter-为什么在更改选项卡时输入框仍然保留?

[英]Python tkinter - Why does the entry box stay when I change tab?

I am new to using tkinter. 我是使用tkinter的新手。 I am basically trying to make a script that uses tabs/notebook tabs. 我基本上是想制作一个使用选项卡/笔记本选项卡的脚本。

I have an entry box and it won't disappear when I change tabs, why? 我有一个输入框,当我更改标签时它不会消失,为什么?

Code: 码:

import tkinter
from tkinter import ttk

win = tkinter.Tk()

win.geometry("500x500")

tab = ttk.Notebook(win)

page1 = tkinter.Frame(tab)
page2 = tkinter.Frame(tab)
page3 = tkinter.Frame(tab)

tab.add(page1, text="Page1")
tab.add(page2, text="Page2")
tab.add(page3, text="Page3")

tab.grid(sticky="W")

entry1 = tkinter.Entry(win)
entry1.insert(0, "Test Entry")
entry1.grid(row=1, column=0, sticky="W")

win.mainloop()

I don't want something like entry1.forget() I just want everything to disappear when I change tabs. 我不想要类似entry1.forget()之类的东西,我只希望在更改标签时所有内容都消失。

Can anybody help? 有人可以帮忙吗?

You have to create the Entry inside the tab and not the window. 您必须在选项卡而不是窗口中创建Entry So just change the line: 因此,只需更改以下行:

entry1 = tkinter.Entry(win)

into: 成:

entry1 = tkinter.Entry(page1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在for循环中迭代时如何更改tkinter中每个输入框的名称? - How to change the name of each entry box in tkinter when iterating in a for loop? python中tkinter输入框中的条件 - condition in entry box in tkinter in python 带输入框的 Python Tkinter askopenfile - Python Tkinter askopenfile with entry box 在Python中关闭Tkinter Entry Box - Closing a Tkinter Entry Box in Python 单击按钮时如何添加新的输入框(Python,Tkinter) - How to add a new entry box when clicking a button (Python, Tkinter) 为什么&lt; <ListboxSelect> &gt;双击Entry小部件时,在Python的Tkinter触发器中虚假绑定? - Why does <<ListboxSelect>> binding in Python's Tkinter trigger spuriously when double clicking an Entry widget? 为什么入口小部件在这种情况下不起作用我把它放在一个框架中,tkinter-python - Why does the entry widget not work in this case i put it in a frame, tkinter-python 为什么在使用Tkinter时Python会说未定义“ App”? - Why does Python say that 'App' is not defined when I use Tkinter? Python &amp; Tkinter。 我希望循环中的一个按钮在按下一次时变为红色并保持红色 - Python & Tkinter. I would like one of my buttons in my loop to change red & stay red when pressed once 使用python Tkinter时,如何在显示相同输入文本的同一个类中停止两个输入框? - When using python Tkinter, how can I stop two entry box's in the same class showing the same input text?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM