简体   繁体   中英

Why won't Python script run after computer restart?

After a restart my script won't work anymore.

It worked before. Windows popping up, things needed to typed in and there was a result which I was happy with (like v0.9-alpha-happy). Now it yells at me.

import random
import tkinter as tk
from tkinter import simpledialog
from tkinter import messagebox
from tkinter import *

alleSpieler = []
team_eins = []
first_window = tk.Tk
first_window.withdraw()

def main():
    global alleSpieler, i, x

    i = 1

    x = simpledialog.askinteger("Spieleranzahl", "Anzahl der Spieler: ")

    if x % 2 == 0:
        while i < x + 1:
            spieler = simpledialog.askstring("Spielername", "Gib Spielername {} ein: ".format(i))
            alleSpieler.append(spieler)
            i = i + 1
    else:
        messagebox.showinfo("Nope", "Bitte gib eine gerade Anzahl von Spielern ein!")
        main()


def sec():
    j = 1
    while j <= len(alleSpieler):
        random_name = random.choice(alleSpieler)
        team_eins.append(random_name)
        alleSpieler.remove(random_name)
        j = j + 1


def teams():
    root = Tk()
    t = Text(root)
    for n in team_eins:
        t.insert(END,"Team 1: " + n + "\n")
    for n in alleSpieler:
        t.insert(END,"Team 2: " +  n + "\n")
    t.pack()
    root.mainloop()

main()
sec()
team1()

And the error(s):

/Users/benediktrautenberg/PycharmProjects/TeamGenerator/venv/bin/python /Users/benediktrautenberg/PycharmProjects/TeamGenerator/Generator.py
Traceback (most recent call last):
  File "/Users/benediktrautenberg/PycharmProjects/TeamGenerator/Generator.py", line 48, in <module>
    main()
  File "/Users/benediktrautenberg/PycharmProjects/TeamGenerator/Generator.py", line 17, in main
    x = simpledialog.askinteger("Spieleranzahl", "Anzahl der Spieler: ")
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/simpledialog.py", line 343, in askinteger
    d = _QueryInteger(title, prompt, **kw)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/simpledialog.py", line 271, in __init__
    Dialog.__init__(self, parent, title)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/simpledialog.py", line 137, in __init__
    if parent.winfo_viewable():
AttributeError: 'NoneType' object has no attribute 'winfo_viewable'

Process finished with exit code 1

All I did to solve this error was:

first_window = Tk()
first_window.withdraw()

You forgot the () near Tk , so your not actually instantiating it properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM