Hiding widgets using self.grid() in Tkinter

While creating a username/password confirmation using the tkinter library, I encountered an issue where the widgets are no longer displayed.

"""
Password entry/confirmation class
"""
from tkinter import *

class Menu:
    def __init__(self,master):

        frame = Frame(master)
        frame.pack()

        title_username = Label(master, text="User Name")
        title_username.grid(row=0, column=0)

        title_password = Label(master, text="Password")
        title_password.grid(row=1, column=0)

        global username
        username = Entry(master, bd=5)
        username.grid(row=0, column=1)

        global password
        password = Entry(master, bd=5)
        password.grid(row=1, column=1)

        confirm_username = Button(master, text="Done",
                                  fg="black",command=self.get_username)
        confirm_username.grid(row=0, column=2)

        confirm_password = Button(master, text="Done",
                                  fg="black",command=self.get_password)
        confirm_password.grid(row=1, column=2)

    def show_all(self):
        self.root.update()
        self.root.deiconify()

    def get_username(self):
        global username
        username = username.get()
        print(username)

    def get_password(self):
        global password
        password = password.get()
        print(password)

root = Tk()
app = Menu(root)
root.mainloop()

The issue stemmed from using grid() instead of pack(), resulting in the widgets not being displayed. (Requiring the declaration of 'global' twice for each variable does not pose a problem)

Answer №1

The initial frame (variable frame) is being placed in master, with widgets such as pack. Subsequent widgets are also being added to master, using grid. This setup may lead to program freezing as grid attempts to arrange the widgets, pack detects changes and tries to rearrange them, causing a loop.

It seems likely that the intention of the code was to place items like title_username and title_password in frame instead of master, given no other use for frame is apparent.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for retrieving information from custom_export within Otree?

Currently, I am experimenting with utilizing ExtraModel and custom_export to extract information from the live_pages. However, after accessing the devserver and examining the data tab, I can't seem to locate the exported data. Furthermore, when I down ...

Python Selenium - failing to insert dynamically generated data into the DOM

I've been working with Python Selenium and have encountered a small issue. Here's the code I'm using: driver = webdriver.PhantomJS() #Alternatively, you can use driver = webdriver.Chrome() driver.get("my_url") driver.find_element_by_xpath(" ...

"Is there a way to convert a collection of lists into JSON format while

Here is a collection of lists including names, scores, and other data: [['Edan Daniele', '12.61', '5.00', '9.22', '1.50', '60.39', '16.43', '21.60', '2.60', '35 ...

Selenium Error: Unresolved attribute reference for class "list" with ".text"

https://www.selenium.dev/documentation/webdriver/elements/information/#text-content As per the guidance provided by Selenium: # Opening the specified URL driver.get("https://www.example.com") # Extracting text from the element text = driver.find_element( ...

Transform nested JSON key value pairs into a flat structure for easy conversion to a CSV file

I have a JSON file with some unique nested label/value pairs. Here's a snippet of the data: { "total_count":10000, "count_from":1, "count_to":1000, "contacts":[ { "contact_id":"ABC123", "contact_last_name":"Last nam ...

Using Selenium to extract data from a table in Python

I am currently exploring web scraping techniques using Python's Selenium library. My goal is to extract data from a table on a website using Selenium. Since I am still learning Python and Selenium, please bear with me if my code seems amateurish. f ...

Utilizing Python's regular expressions for parsing and manipulating Wikipedia text

I am attempting to convert wikitext into plain text using Python regular expressions substitution. There are two specific formatting rules for wiki links: [[Name of page]] [[Name of page | Text to display]] (http://en.wikipedia.org/wiki/Wikipedia:Cheat ...

Error encountered while attempting to parse schema in JSON format in PySpark: Unknown token 'ArrayType' found, expected JSON String, Number, Array, Object, or token

Following up on a previous question thread, I want to thank @abiratis for the helpful response. We are now working on implementing the solution in our glue jobs; however, we do not have a static schema defined. To address this, we have added a new column c ...

Decreasing window size near boundary for smoothing functions with fixed endpoints

I'm in search of a solution that can perform simple boxcar smoothing with the added requirement of accepting a boundary condition. Specifically, I need a function, either pulled from an existing library or written in Python for performance, that can h ...

Delicious Tastypie Traits and Associated Titles, Void Attribute Exception

I encountered the following error message: The object '' is throwing an empty attribute 'posts' error which does not allow a default or null value. My goal is to retrieve the number of 'votes' on a post and return it in my m ...

Having trouble executing a flawless loop roll

I have successfully developed a Python script using Selenium to extract phone numbers from a website. The process involves entering city names into a search box and hitting the search button. I tested it with "Miami" as the city name, but encountered an is ...

Can you create a histogram plot with a kernel density estimation using Pandas?

I am working with a Pandas dataframe (Dt) that has the following structure: Pc Cvt C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 0 1 2 0.08 0.17 0.16 0.31 0.62 0.66 0.63 0.52 0.38 1 2 2 0.0 ...

What is the best way to implement a single line of code across multiple functions?

As a newcomer to Python, I have a question. Is it possible for all functions to share the same line of code? with open(filename, 'r') as f: Since this line of code is identical in all three functions, is there a way to avoid repeating it without ...

Acquire the browser token using Python

Is there a way to retrieve the Auth token from the browser using Selenium? I'm currently working on creating a browser instance and need to access the tokens in the network tab. Any suggestions on how to achieve this? ...

Guide to Python's PEP standards for using dictionary keys

Is there a recommended style guide, like PEP, for the format of dictionary keys? In particular, should I use upper or lower case letters and how should I handle multiple words (with spaces or underscores)? For instance, is it considered good practice to ...

Tips for bypassing captcha and avoiding Selenium detection

I wrote a Python script that logs into a specific page (sso.acesso.gov.br) using certain credentials and then typically solves a captcha using the 2Captcha API. However, recently I have been encountering an error after solving the captcha, even when I do ...

What is the best way to adjust the time intervals in a time series dataframe to display average values for

I understand that pandas resample function has an **hourly** rule, but it currently calculates the average for each hour across the entire dataset. When I use the method (df.Value.resample('H').mean()), the output looks like this: Time&d ...

Python Selenium cannot locate button within an iframe

click here for imageI am trying to interact with the "바카라 멀티플레이" button located at the center of the website. Even after switching into an iframe, I am unable to detect the button. How can I achieve this? from selenium import webdriver im ...

Tips for dispersing a Python application as a standalone:

My goal is to share my Python application with my colleagues for use on Linux systems. However, they do not have admin privileges to install the necessary module dependencies. I want them to be able to simply extract the application and run the main.py scr ...

Sending JSON data with Python and fetching the response

I've been working on a Python script to make a post request, but I'm not receiving any response. Everything seems correct in my code, so I suspect there might be an issue with the service itself causing the lack of response. Can anyone spot if th ...