Ich habe ein Problem beim Erstellen eines Popup-Fensters für ein Programm.Wie erstelle ich ein Popup-Fenster in tkinter?
Code:
from tkinter import *
from tkinter import ttk
import tkinter as tk
def popupBonus():
popupBonusWindow = tk.Tk()
popupBonusWindow.wm_title("Window")
labelBonus = Label(popupBonusWindow, text="Input")
labelBonus.grid(row=0, column=0)
B1 = ttk.Button(popupBonusWindow, text="Okay", command=popupBonusWindow.destroy())
B1.pack()
class Application(ttk.Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master)
mainwindow = ttk.Frame(self)
self.buttonBonus = ttk.Button(self, text="Bonuses", command=popupBonus)
self.buttonBonus.pack()
Der Code erzeugt ein Fenster mit einem Button und wenn Sie die Taste drücken, es sollte ein Popup-Fenster mit dem Titel „Fenstern“, Text „Input“ erzeugen, und eine Schaltfläche "Okay" sagen, um das Popup-Fenster zu verlassen und zum Hauptfenster zurückzukehren. Allerdings bekomme ich diesen Fehler.
Traceback (most recent call last):
File "D:\Softwares\Python 3.6.0\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Users\J---- M--\Desktop\Python\GUI-Messagebox 5.py", line 12, in popupBonus
B1 = ttk.Button(popupBonusWindow, text="Okay", command=popupBonusWindow.destroy())
File "D:\Softwares\Python 3.6.0\lib\tkinter\ttk.py", line 614, in __init__
Widget.__init__(self, master, "ttk::button", kw)
File "D:\Softwares\Python 3.6.0\lib\tkinter\ttk.py", line 559, in __init__
tkinter.Widget.__init__(self, master, widgetname, kw=kw)
File "D:\Softwares\Python 3.6.0\lib\tkinter\__init__.py", line 2293, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: NULL main window
Ich habe keine Ahnung, was das Problem ist. Ich habe versucht, für 4 Stunden eine Antwort zu finden und habe im Grunde aufgegeben.
Auch ich möchte nicht tkinter die Messagebox-Funktion verwenden, weil ich nicht das Ausrufezeichen Bild will und ich mehrere Kontrollkästchen in das Popup-Fenster später einschließen möchten.
a) nicht mehr als eine Instanz von 'Tk' erstellen, und b) finden Sie unter http: // effbot.org/tkinterbook/tkinter-dialog-windows.htm –
'command =' erwartet Funktionsname (Callback) - es bedeutet ohne '()'. Nun führst du 'popupBonusWindow.destroy()' und sein Ergebnis - wahrscheinlich 'None' - zu' command = ' – furas