Python Forum
[PyGUI] My GUI crashes after command
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGUI] My GUI crashes after command
#1
Hello. I a new to python and this forum. I am making a little game and I do not understand why but my GUI crashes after it completes the code or I want to close it. Can someone help?
from tkinter import *
import random
import tkinter
import time
def gamemain():
    print("Once was a nice village. It lived in prosperity.")
    time.sleep(1)
    print("The village was attacked by witches. All village was insalved.")
    time.sleep(1)
    print("But you managed to survive. Witches deleted your memory with their magic.")
    time.sleep(1)
    PlayersName = input("What will you name your self? ")
    print("Ok " + PlayersName)
    time.sleep(1)
    print("Go and save your people. After all you were a... KING!")
    print("LEVEL 1")
    print("__________________________________________________________________________")
    print("You are checking the houses for survivors and you see 3 doors that magicly appered")
    doors = input("Which door are you going to open?")
    window = Tk()
    photo = PhotoImage(file="doors.jpg")
    label = Label(window, image=photo)
    label.pack()
    window.mainloop()

def start1():
    secCheck = input("Please show me your lisence mister:")
    if secCheck == "MonkeIsGreat":
        print("Lets begin!")
        command = gamemain()
    else:
        print("Sorry mister. I can not let you go.")



def close():
    exit()


print("SIMPLICITY by NAPALM")
window = Tk()
window.geometry = "100X100"
buttonA = Button(window, text="START", command=start1)
buttonB = Button(window, text="CLOSE", command=close)
buttonA.pack()
buttonB.pack()
window.mainloop()
window.destroy()
Reply
#2
When you have an error you should post the error message and error trace. I cannot run your program to find the error because you program has dependencies (image files) that I do not have.

I'm pretty sure your error results from calling Tk() to make a second window. Tk() is not how you make windows in tkinter. Tk() is how you initialize tkinter, and it also makes the FIRST WINDOW. Only call Tk() once in your application. Additional windows can be made using dialogs:

https://docs.python.org/3/library/dialog.html

or TopLevel() to make and additional "top level" windows.

https://www.pythontutorial.net/tkinter/t...-toplevel/
MLGpotato likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  GUI crashes flash77 3 925 Jul-26-2023, 05:09 PM
Last Post: flash77
  [Tkinter] Clicking on the button crashes the TK window ODOshmockenberg 1 2,248 Mar-10-2022, 05:18 PM
Last Post: deanhystad
  [PyQt] App crashes when reopening a subwindow JayCee 13 5,072 Aug-04-2021, 01:51 AM
Last Post: JayCee
  [PyQt] PyQT5 Thread crashes after a while Suresh 0 1,982 Jul-21-2020, 07:53 AM
Last Post: Suresh
  PyQt5 : Interpreter Crashes While Initializing Message Box iMuny 7 5,730 Aug-29-2019, 01:38 PM
Last Post: iMuny

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020