I'm making a Treasure Island type game and I'm trying to make the screen follow the text e.g if the text goes off the screen the screen automatically scrolls down to fit in the text. I've tried various types of this by different people mostly scrollbars but I can't get any to work, I currently have a "scrollbar" set up but it doesn't work.
here's the code:
import tkinter
import tkinter as ttk
from Treasure_Island_V2_art import Treasure_Chest, Pirate_Ship
window = tkinter.Tk()
window.title("Treasure Island")
window.attributes('-fullscreen', True)
window.config(bg = "black")
window.grid_columnconfigure(0, weight=1)
window.grid_rowconfigure(0, weight=1)
text = tkinter.Text(window, height=10)
text.grid(row=0, column=0, sticky=tkinter.EW)
scrollbar = ttk.Scrollbar(window, orient='vertical', command=text.yview)
scrollbar.grid(row=0, column=1, sticky=tkinter.NS)
text['yscrollcommand'] = scrollbar.set
logo = tkinter.Label(window, text = '''
| | | |
_________|________________.=""_;=.______________|_____________________|_______
| | ,-"_,="" `"=.| |
|___________________|__"=._o`"-._ `"=.______________|___________________
| `"=._o`"=._ _`"=._ |
_________|_____________________:=._o "=._."_.-="'"=.__________________|_______
| | __.--" , ; `"=._o." ,-"""-._ ". |
|___________________|_._" ,. .` ` `` , `"-._"-._ ". '__|___________________
| |o`"=._` , "` `; .". , "-._"-._; ; |
_________|___________| ;`-.o`"=._; ." ` '`."\` . "-._ /_______________|_______
| | |o; `"-.o`"=._`` '` " ,__.--o; |
|___________________|_| ; (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._ " `".o|o_.--" ;o;____/______/______/____
/______/______/______/_"=._o--._ ; | ; ; ;/______/______/______/_
____/______/______/______/__"=._o--._ ;o|o; _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/_____ /
''')
logo.grid()
logo.config(font=('arial', 15), fg = "green", bg = "black")
line1 = tkinter.Label(window, text=("Welcome to Treasure Island,\n"
"Your goal is to find the buried Treasure!"))
label1 = tkinter.StringVar()
a = tkinter.Label(textvariable=label1, font = ('arial', 20), fg = "blue", bg = "black")
a.grid()
for i in line1.cget("text"):
a=label1.get()
label1.set(a+i)
window.after(50)
window.update()
space = tkinter.Label(window, text=" \n \n ")
space.grid()
space.config(bg = "black")
line2 = tkinter.Label(window, text="You wake up to find yourself laying in the middle of a deserted beach,\n"
"you feel hungry but you see something that catches your eye.")
label2 = tkinter.StringVar()
b = tkinter.Label(textvariable=label2, font = ('arial', 20), fg = "blue", bg = "black")
b.grid()
for i in line2.cget("text"):
b=label2.get()
label2.set(b+i)
window.after(30)
window.update()
window.mainloop()