If you have any questions, comments or issues with this project please post them here!
So I have typed the code out exactly as it is within the lesson, but there is no text window like there should be. I tested the code outside of Replit just to make sure it wasnât a bug, but it didnât work there either. It seems like there is something missing.
Can you please share the code? I may or may not be up to day 66
import tkinter as tk
window = tk.Tk()
window.title(âGroovey Botâ) # Sets the name of the window in the border
window.geometry(â300x300â) # Sets the size of the window in pixels
label = 0
def updateLabel():
global label
label += 1
hello[âtextâ] = label
hello = tk.Label(text = label) # Creates a text box
hello.pack() # âpackâ places the element on the screen
button = tk.Button(text = âDonât Click me!â, command = updateLabel) # Creates a button
button.pack()
text = tk.Text(window, height=1, width=50)
text.pack
tk.mainloop()
There should be nothing being printed. There are no print statements so its working as intended. @DavidAtReplit can say if this is intentional.
Itâs supposed to put a text box that you can type into in the main window.
The next step in the lesson is using information that is typed into that text box.
Iâll grab my original solution repl and take a look
Is this not the code we put in the solution? https://replit.com/@DavidAtReplit/Day-66-Solution-1#main.py
And just to clarify the text box in this is just a label, itâs not meant to be typed into - the buttons are supposed to do the work
Yes, I figured it out. the text.pack was missing the () at the end. I watched the video again and noticed that it was in the video, but not in the tutorial window.
And the issue was before I got to the project, it was on the 2nd slide âAdding Textâ
My Output is buffering forever and not showing anything
Does anybody know what the problem might be?
Replit as a whole (more specifically web hosted repls) is having issues right now.
Hi @surfineer and @Firepup650 thanks for your messages. Are you still experiencing problems? If so can you link to your Repl here please?
Hi @IanAtReplit , itâs very flaky.
This week was working fine, but today Iâm on the final tkinter project and itâs not running anymore (Output is loading and loading but nothing happens)
Hereâs the link to my repl (unfinished!):
main.py - Day 69: Visual Novel - Replit
I do see the first two screens and buttons work on the first screen
I switched to PyCharm and finished my code there and it works
SO Iâm gonna close the tkinter chapter now! Woohoo
Thank you for posting that! I had the same issue and couldnt figure out what I did wrong lol. It looks like it was missing for lots of the text.
I got stuck for a while in two places on this lesson:
In the tutorial, the first two code demonstrations in the âAdding Textâ section and the first one in âPlacing Itemsâ have a text.pack missing the brackets. (Thanks MrKrinle for posting about it)
I also tried to pass variables through my button commands, but this caused the command to run when the program started and do nothing when the button was pressed. I figured out a fix from this.
this is not working even after copy pasting everything in the lesson. The code is not adding the numbers I put in. Please help @DavidAtReplit
import tkinter as tk
window = tk.Tk()
window.title("Hello World")
window.geometry("300x300")
label = 0
def updateLabel():
global label
number = text.get("1.0","end") # Gets the number from the text box (starting at the first position and going to the end.) and stores in the number variable
number = int(number) #Casts to an integer. I've done this on a separate line to prevent the line above getting too complex, but you can combine the two.
label += number # Adds the number from the text box to the one in the label.
hello["text"] = label
hello = tk.Label(text = label)
hello.pack()
button = tk.Button(text = "Click me!", command = updateLabel)
button.pack()
text = tk.Text(window ,height=1, width = 50)
text.pack()
tk.mainloop()
Try this fix of your code, itâs not feature-complete but will work
import tkinter as tk
def updateLabel():
number = text.get("1.0", "end-1c") # Get the number from the text box (excluding the newline character)
try:
number = int(number) # Convert the number to an integer
global label
label += number # Add the number from the text box to the existing label
hello.config(text=label) # Update the label text
except ValueError:
pass
window = tk.Tk()
window.title("Hello World")
window.geometry("300x300")
label = 0
hello = tk.Label(window, text=label)
hello.pack()
button = tk.Button(window, text="Click me!", command=updateLabel)
button.pack()
text = tk.Text(window, height=1, width=50)
text.pack()
tk.mainloop()