Untitled

mail@pastecode.io avatar
unknown
python
a month ago
1.2 kB
1
Indexable
Never
import tkinter as tk

#This represents your pet's current level.
level = 0


# This code updates the level variable below.
def train_pet():
  global level
  level += 1

  #This sets the text in the pet_status variable to the new level.
  pet_level.set("PET LEVEL: " + str(level))

  #This prints the pet's level to the console.
  print(level)


# Create the main window
root = tk.Tk()
root.title("Virtual Pet")

#This create a string variable
pet_status = tk.StringVar()
pet_status.set("I AM THE GREATEST PET EVER")

#This sets up the label that will hold the pet status. It
# allows you to set the font, font size, etc.
pet_label = tk.Label(root, textvariable=pet_status, font=("Helvetica", 16))

#This packs the label into the window.
pet_label.pack()

pet_level = tk.StringVar()
pet_level.set("PET LEVEL: 0")
pet_level_label = tk.Label(root,
                           textvariable=pet_level,
                           font=("Helvetica", 16))
pet_level_label.pack()

#This sets up the button that will "train" the pet.
train_button = tk.Button(root, text="Train Pet", command=train_pet)
train_button.pack()


#This starts the loop that will run the window.
root.mainloop()
Leave a Comment