ist definiert. Der Code, den ich in der Frage gezeigt habe war nur ein Ausschnitt. Hier ist einmal aktuell das ganze Programm, ist aber nicht wichtig und ich sag schonmal gleich: Für Profi-Informatiker herrscht Herzinfakt-Gefahr!
Code: Alles auswählen
from tkinter import *
from PIL import Image, ImageTk
from pathlib import Path
BASEPATH = Path(__file__).parent
def setup_window(windowtitle):
root = Tk()
root.geometry("1450x770+0+0")
root.title(windowtitle)
root.resizable(False, False)
return root
root1 = Tk()
root1.geometry("1450x770+0+0")
root1.title("Warnung!")
root1.resizable(False, False)
root1.iconbitmap(BASEPATH / "662218.ico")
label1_1 = Label(root1, text="Dieses Spiel wurde für eine Anzeigen-Skalierung von 125 Prozent optimiert. \nEs kann auch mit einer anderen Größen-Einstellung fortgefahren werden, jedoch können dabei möglicherweise Fehler auftreten.", font=20)
label1_1.place(x=100, y=300)
button1_1 = Button(root1, text="Verstanden", fg="green", font=20, command=root1.destroy)
button1_1.place(x=680, y=380)
scaleimage1 = ImageTk.PhotoImage(Image.open(BASEPATH / "Anmerkung192106.png"))
label1_2 = Label(root1, image=scaleimage1)
label1_2.place(x=550,y=440)
root1.mainloop()
root2 = setup_window("Name")
mainimage = ImageTk.PhotoImage(Image.open(BASEPATH / "MapGanzRoh.png"))
button_pic_go_city = ImageTk.PhotoImage(Image.open(BASEPATH / "b12121212neu.png"))
label2_1 = Label(root2, image=mainimage)
label2_1.place(x=0,y=0)
button_2_1 = Button(root2, text="Spiel Beenden", fg="red", command=root2.destroy)
button_2_1.place(x=1310, y=725)
def open_malay():
root_malay = setup_window("Malay")
root_malay.mainloop()
root2.destroy()
button_malay = Button(root2, text="", bg="LightGrey", image=button_pic_go_city, command=open_malay)
button_malay.place(x=364, y=49)
button_nabas = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_nabas.place(x=402, y=75)
button_libertad = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_libertad.place(x=370, y=112)
button_pandan = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_pandan.place(x=445, y=134)
button_kalibo = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_kalibo.place(x=587, y=167)
button_banga = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_banga.place(x=562, y=226)
button_batan = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_batan.place(x=670, y=231)
button_roxas_city = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_roxas_city.place(x=805, y=241)
button_sapi_an = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_sapi_an.place(x=712, y=268)
button_estancia = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_estancia.place(x=1015, y=291)
button_pontevedra = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_pontevedra.place(x=879, y=315)
button_culasi = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_culasi.place(x=445, y=307)
button_panay = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_panay.place(x=678, y=368)
button_sara = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_sara.place(x=923, y=382)
button_tibiao = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_tibiao.place(x=420, y=380)
button_barbaza = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_barbaza.place(x=422, y=420)
button_dumarao = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_dumarao.place(x=772, y=410)
button_concepcion = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_concepcion.place(x=1003, y=425)
button_passi_city = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_passi_city.place(x=751, y=450)
button_ajuy = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_ajuy.place(x=929, y=475)
button_bugasong = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_bugasong.place(x=474, y=488)
button_lambunao = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_lambunao.place(x=632, y=499)
button_banate = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_banate.place(x=831, y=543)
button_cabatuan = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_cabatuan.place(x=677, y=594)
button_patnongon = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_patnongon.place(x=436, y=587)
button_belison = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_belison.place(x=383, y=628)
button_san_jose = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_san_jose.place(x=366, y=683)
button_iloilo_city = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_iloilo_city.place(x=707, y=698)
button_hamtic = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_hamtic.place(x=400, y=735)
button_miagao = Button(root2, text="", bg="LightGrey", image=button_pic_go_city)
button_miagao.place(x=498, y=726)
root2.mainloop()
dem Code, denn sie benötigen Variablen, die weiter oben im Code definiert wurden, und müssen dann aber wiederum zum Beispiel vor einem Button liegen, der die Funktion ausführt.
Der Button-Definitions-Teil würde sich meiner Meinung nach"nur" um die Hälfte verkürzen lassen, wenn man es ordentlich macht. Ich leg nunmal in meiner Anfangsphase im Programmieren weniger Wert auf Aussehen als auf Funktionalität.
Im gezeigten Programm wurden noch keine Änderungen bezüglich den mehreren root-Objekten gemacht, da kümmer ich mich gleich darum.