Python Forum
[Tkinter] Tkinter delete values in Entries, when I'm changing the Frame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tkinter delete values in Entries, when I'm changing the Frame
#7
I got it right! Sort of.

Here's a shorter example that demonstrates the problem:
import tkinter as tk
 
class Win1:

    def __init__(self, master):
        self.master = master
        self.master.title("Gap Assessment")
        self.topFrame = tk.Frame(self.master)
        self.topFrame.grid(row=0, column=0, sticky='news', ipady = 5)
        self.A_GapFrame = tk.Frame(self.master)

        # Create a Tkinter variable
        self.gapType = tk.StringVar(self.master)
        # Dictionary with options
        self.choiceGap =  ['AFrame']
        # self.choiceGap = sorted(self.choiceGap)
        self.gapType.set('') # set the default option
        self.ctngMenu = tk.OptionMenu(self.topFrame, self.gapType, *self.choiceGap, command=self.chioseGap_handle)
        self.ctngMenu.grid(row = 1, column =2)
 
    def chioseGap_handle(self, selected):
        self.A_GapFrame.tkraise()
        self.subframe_AGap()
        self.A_GapFrame.grid(row=2, column=0, sticky='news')
 
    def subframe_AGap(self):
        self.jobNameA_text = tk.StringVar()
        self.jobNameA_entry = tk.Entry(self.A_GapFrame, textvariable = self.jobNameA_text)
        self.jobNameA_entry.grid(row=1, column=0, sticky='news') 
        print('A', self.jobNameA_entry)
             
root = tk.Tk()
root.geometry("+50+50")
app = Win1(root)
root.mainloop()
When I run this and make selections from the combo box I see this in the console:
Output:
A .!frame2.!entry A .!frame2.!entry2 A .!frame2.!entry3 A .!frame2.!entry4
Each time I select a frame it creates a new Entry widget. Even if this didn't cause the old Entry widget to be deleted it would still cause previously entered text to disappear behind the new Entry widget that is drawn over the top.

You need to rewrite you code so it only creates one entry widget for each frame.
Reply


Messages In This Thread
RE: Tkinter delete values in Entries, when I'm changing the Frame - by deanhystad - Jul-29-2020, 04:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 1,030 Jan-16-2024, 06:44 PM
Last Post: rob101
  [Tkinter] Help running a loop inside a tkinter frame Konstantin23 3 1,603 Aug-10-2023, 11:41 AM
Last Post: Konstantin23
  tkinter mapview in a frame janeik 2 1,344 Jun-22-2023, 02:53 PM
Last Post: deanhystad
  [Tkinter] Trouble changing Font within tkinter frame title AnotherSam 1 4,156 Sep-30-2021, 05:57 PM
Last Post: menator01
  tkinter frame camera opencv Nick_tkinter 9 5,484 Mar-21-2021, 06:41 PM
Last Post: Nick_tkinter
  [Tkinter] changing the frame colour nick123 4 16,650 Jul-24-2020, 07:32 AM
Last Post: LegacyCoding
  Why is wx.NO_BORDER changing panels within a frame MeghansUncle2 4 2,573 Jul-12-2020, 12:32 PM
Last Post: Yoriz
  [Tkinter] tkinter, dropdowns with changing options Sheepykins 4 9,852 Jul-03-2020, 06:06 AM
Last Post: jdos
  changing tkinter label from thread nanok66 3 7,399 Jun-07-2020, 01:37 AM
Last Post: nanok66
  How to disable focus on Frame in Tkinter? szafranji 1 3,038 May-13-2020, 10:45 PM
Last Post: DT2000

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020