#๐Ÿ”’ need help with my tkinter GUI any help would be appreciated

23 messages ยท Page 1 of 1 (latest)

lethal needle
#

i would like to add a waiting system that's why i have time imported i want it to wait for input from the entry its pretty simple i am just practicing

import tkinter as tk 
import time

window = tk.Tk()
window.title("number game")

label = tk.Label(window, text="choose a number between 1 and 100")
label.pack()

entry = tk.Entry(window)
entry.pack()

def get_input():
    value = entry.get()
    print("stored-varible = ", value)
    
button = tk.Button(window, text="Submit", command=get_input)
button.pack()



label = tk.Label(window, text=f"your number was, {value}")
label.pack()

window.mainloop()
rotund pantherBOT
#

@lethal needle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tiny forge
#

You have the command=get_input on your submit button. That at least waits for a "submit". You could have your get_input "do nothing" if the entry.get() call returns an empty string?
Otherwise you'll need to be more clear about what you're really waiting for.

lethal needle
#

when i run it with time.sleep(1) it does not do anything is thare other command i should use also about the variable situation i want it to print p out the entry input after the waiting time from my button it alwasy says value is not defined

tiny forge
#

time.sleep(1) just pauses for 1 second. Nothing else.

You should show your entrie error message for the "value not defined" thing.

#

!traceback

rotund pantherBOT
#
Traceback

Please provide the full traceback for your exception in order to help us identify your issue.
While the last line of the error message tells us what kind of error you got,
the full traceback will tell us which line, and other critical information to solve your problem.
Please avoid screenshots so we can copy and paste parts of the message.

A full traceback could look like:

Traceback (most recent call last):
  File "my_file.py", line 5, in <module>
    add_three("6")
  File "my_file.py", line 2, in add_three
    a = num + 3
        ~~~~^~~
TypeError: can only concatenate str (not "int") to str

If the traceback is long, use our pastebin.

lethal needle
#

sure here you go

#
Traceback (most recent call last):
  File "my_file.py", line 5, in <module>
    add_three("6")
  File "my_file.py", line 2, in add_three
    a = num + 3
        ~~~~^~~
TypeError: can only concatenate str (not "int") to str
#

wrong one

#
Traceback (most recent call last):
  File "/home/carsonb/mu_code/Code/number_game.py", line 20, in <module>
    label = tk.Label(window, text=f"your number was, {value}")
                                                      ^^^^^
NameError: name 'value' is not defined. Did you mean: 'False'?
#

thats the one

tiny forge
#

I'm guess it's this line:

label = tk.Label(window, text=f"your number was, {value}")

The value variable exists only inside the get_input function, and only while that function is running i.e. for a tiny fraction of a second.
You could use text=f"your number was, {entry.get()}") instead to consult the entry widget.
But this is set _at the time you define the Label. So it doesn't update.
What you probably want is for get_input to update the text of the Label when it is called.

lethal needle
#

alright thanks alot ill try that

tiny forge
#

I think you can do that as label['text'] = f"your number was, {value}" inside the get_input function.

#

That would work because inside the function you do have access to the value local variable.

lethal needle
#

this is what came out ```py
def get_input(label = ['text'] = f"your number was, {value}"):
^
SyntaxError: invalid syntax

#

ill cherck this link out

tiny forge
#

I was thinking:

def get_input():
    value = entry.get()
    print("stored-varible = ", value)
    label['text'] = f"your number was, {value}"
#

i.e. updating the label is one of the things which happens inside get_input

rotund pantherBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.