Day 069 - Project 69 : Visual Novel builder

If you have any questions, comments or issues with this project please post them here!

Hey , any sleep token fans around ? :smiley:
I made a sleep token visual novel for day 69 , if someone wants to check it go here :
https://replit.com/@EvGoumiz/Visual-Sleep-Token-Novel
Cheers

1 Like

Hi all,

I’ve been working on day 69 (visual novel builder) of the 100 days of code all day but have a minor issue that I don’t know how to solve. My starting screen displays all the buttons when it should display only the first two but once the loop completes the error disappears.

Can anyone help please? Link to my project here: https://replit.com/@ZaraKhan23/Day69100Days#main.py

It looks like you have defined all your buttons but packed them all as well which means they will get drawn on the main screen.

The reason why it works when the restart button is clicked is because every button packed is forgotten and the first two buttons only are packed.

The below code should work (notice how only the first two buttons are packed?)

import tkinter as tk

window = tk.Tk()
window.title("A Visual Novel of Isiah's Weekend In Stockholm")
window.geometry("600x400")

story = "Isiah wakes up on a Saturday morning\n"

def isnow():
  global story
  canvas.itemconfig(container, image=snow)
  story= ("meet stella outside and play in the snow\n")
  storyLabel ["text"] = story
  button1.pack_forget()
  button2.pack_forget()
  button3.pack()
  button4.pack()

def istella():
  global story
  canvas.itemconfig(container, image=stella)
  story= ("skip to see what stella is up to\n")
  storyLabel ["text"] = story
  button1.pack_forget()
  button2.pack_forget()
  button5.pack()
  button6.pack()

def ichill():
  global story
  canvas.itemconfig(container, image=chill)
  story= ("chill on the sofa\n")
  storyLabel ["text"] = story
  button3.pack_forget()
  button4.pack_forget()
  restartButton.pack()

def iread():
  global story
  canvas.itemconfig(container, image = read)
  story= ("read a comic book together\n")
  storyLabel ["text"] = story
  button3.pack_forget()
  button4.pack_forget()
  restartButton.pack()

def iorange():
  global story
  canvas.itemconfig(container, image = orange)
  story= ("go out, pick up some oranges and bake an orange cake\n")
  storyLabel ["text"] = story
  button5.pack_forget()
  button6.pack_forget()
  restartButton.pack()

def ibrush():
  global story
  canvas.itemconfig(container, image=brush)
  story = "stay at home and brush each other's hair\n"
  storyLabel["text"] = story
  button5.pack_forget()
  button6.pack_forget()
  restartButton.pack()

def restart():
  global story
  canvas.itemconfig(container, image=start)
  story = "Isiah wakes up on a Saturday morning\n"
  storyLabel["text"] = story
  restartButton.pack_forget()
  button1.pack()
  button2.pack() 


start = tk.PhotoImage(file="1.png")
start = start.subsample(4)
snow = tk.PhotoImage(file = "1a.png")
snow = snow.subsample(4)
stella = tk.PhotoImage(file = "1b.png")
stella = stella.subsample(4)
chill = tk.PhotoImage(file = "2a.png")
chill = chill.subsample(4)
read = tk.PhotoImage(file = "2b.png")
read = read.subsample(4)
orange = tk.PhotoImage(file = "3a.png")
orange = orange.subsample(4)
brush = tk.PhotoImage(file = "3b.png")
brush = brush.subsample(4)

canvas = tk.Canvas(window, width =300, height=200)
canvas.pack()
container = canvas.create_image(150,150, image=start)
storyLabel =tk.Label(text=story)
storyLabel.pack()

button1= tk.Button(text ="meet Stella outside to play in the snow", command = isnow)
button1.pack()

button2 = tk.Button(text ="skip to see what Stella is doing in the city", command = istella)
button2.pack()

button3 = tk.Button(text= "chill on the sofa", command = ichill)
button4 = tk.Button(text ="read a comic book together", command = iread)
button5 = tk.Button (text = "pick up some oranges from the farm and bake a small orange cake", command = iorange)
button6 = tk.Button (text = "stay at home and brush each other's hair", command = ibrush)
restartButton = tk.Button(text = "Restart", command = restart)
tk.mainloop()
2 Likes

thank you Mr-PP5. it worked like a charm!