Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:05:04+00:00 2026-06-15T13:05:04+00:00

So I am trying to build a GUI where I enter some information, clear

  • 0

So I am trying to build a GUI where I enter some information, clear the entry fields, and then add new entry fields. However, when I try to clear the frame from the root via grid_remove, the application freezes. The relevant code is below.

import tkinter
from threading import Thread

class PinGui(tkinter.Frame):
    def __init__(self, client):
        self.client = client
        self.root = client.root
        self.add_pin = client.add_pin
        self.end = client.end
        tkinter.Frame.__init__(self, self.root)
        self.grid_widgets()
        self.grid_buttons()
        self.bind_keys()
        self.grid(padx=32, pady=32)

    def grid_buttons(self, b1='Add', b2='Reset', b3='Quit'):
        self.addButton = tkinter.Button(self, text=b1, command=self.validate)
        self.resetButton = tkinter.Button(self, text=b2, command=self.reset)
        self.quitButton = tkinter.Button(self, text=b3, command=self.end)
        self.buttons = [self.addButton, self.resetButton, self.quitButton]
        for i in range(3): self.buttons[i].grid(row=i, column=11)

    def grid_widgets(self):
        widths = [3,3,4,4,6]
        self.pin_vars = []
        self.pin_fields = []
        for i in range(5):
            self.pin_vars.append(tkinter.StringVar())
            self.pin_fields.append(
                tkinter.Entry(self,width=widths[i], textvariable=self.pin_vars[i])
                )
            self.pin_fields[i].grid(row=0, column=2*i, padx=3)
        self.pin_fields[0].focus_set()

    def bind_keys(self):
        self.root.bind_all("<Return>", self.validate)
        self.root.bind_all("<Escape>", self.end)

    def validate(self, args=None):
        self.client.pin = []
        for field in self.pin_fields:
            self.client.pin.append(field.get())
        Thread(target=self.add_pin).start()

    def ungrid(self):
        for field in self.pin_fields: field.grid_remove()
        for button in self.buttons: button.grid_remove()
        self.display.grid_remove()

And:

class PinClient:
    def __init__(self):
        self.root = tkinter.Tk()
        self.gui = PinGui(self)
        self.pins = []

    def add_pin(self):
        self.gui.reset()
        if 'display' in self.__dict__:
            self.pins.append(self.pin)
            self.display.add_pin(self.pin)
            self.ping("Enter PIN for Comp %s:" % len(self.display.col1))
            if len(self.display.col1) > 5:
                self.end() # THIS IS WHERE IT FREEZES
        else:
            self.subject = self.pin
            self.display = Display(self.root, self.pin)
            self.display.grid(row=1, padx=32, pady=32)
            self.ping("Enter PIN for Comp 1:")

    def ping(self, msg):
        self.gui.d_var.set(msg)

    def end(self, args=None):
        self.gui.ungrid()

class Display(tkinter.Frame):
    def __init__(self, master, pin):
        tkinter.Frame.__init__(self, master)
        self.pin = pin
        self.col1 = []
        self.col2 = []
        self.col1.append(tkinter.Label(self, text="Subject:"))
        self.col2.append(tkinter.Label(self, text=self.pin))
        self.grid_widgets()

    def grid_widgets(self):
        self.ungrid()
        for i in range(len(self.col1)):
            self.col1[i].grid(row=i, column=0)
            self.col2[i].grid(row=i, column=1)

    def ungrid(self):
        for i in range(len(self.col1)):
            self.col1[i].grid_remove()
            self.col2[i].grid_remove()

    def add_pin(self, pin):
        self.col1.append(tkinter.Label(self, text="Comp %s:" % len(self.col1)))
        self.col2.append(tkinter.Label(self, text=pin))
        i = len(self.col1)
        self.col1[i-1].grid(row=i, column=0)
        self.col2[i-1].grid(row=i, column=1)

It seems to be somehow related to the threading, but I haven’t been able to find any reason this should freeze. Any help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:05:05+00:00Added an answer on June 15, 2026 at 1:05 pm

    Tkinter is not thread safe. If you do anything in a thread other than the main thread that touches a GUI object then you will get unpredictable results. Almost certainly, it is threading that is causing your problem, since you are trying to access widgets from the worker thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Java GUI and trying to build a simulator. In every
I am trying to build a GUI that has three horizontal sliders that control
I'm trying to build a GUI window in my application. What I'm trying to
I'm trying build an App Engine connected Android application and am having some problems
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
I am trying to build up a GUI interface similar to the figure. Basically,
I am trying to build a simple menu-based GUI with J2ME. The menu entries
Trying to build a GUI application in Java/Swing. I'm mainly used to painting GUIs
I ran into a weird problem while trying to build a Traits GUI that
I am using cmake-gui trying to build opencv but get this error: CMake Error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.