Day 066 - Project 66 : Calculator

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.

2 Likes

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()

1 Like

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”

3 Likes

3 Likes

My Output is buffering forever and not showing anything :anguished:
Does anybody know what the problem might be?

Replit as a whole (more specifically web hosted repls) is having issues right now.

2 Likes

Hi @surfineer and @Firepup650 thanks for your messages. Are you still experiencing problems? If so can you link to your Repl here please?

1 Like

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) :slightly_frowning_face:

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 :relieved:
SO I’m gonna close the tkinter chapter now! Woohoo
:partying_face:

1 Like

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.

1 Like

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()
1 Like