1
プログラムのポップアップウィンドウを作成する際に問題があります。tkinterでポップアップウィンドウを作成するにはどうすればいいですか?
コード:
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()
コードはボタンでウィンドウを生成し、あなたがボタンを押したときに、タイトルの「窓」でポップアップウィンドウを生成することになっています、テキスト「入力」、およびボタンを持っていますポップアップウィンドウを終了してメインウィンドウに戻るには「OK」と言ってください。しかし、私はこのエラーが発生しています。
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
問題の原因はわかりません。私は4時間の答えを見つけようとしており、基本的にあきらめました。
また、私は感嘆符のイメージが不要で、後でポップアップウィンドウ内に複数のチェックボックスを含めるので、tkinterのmessagebox機能を使用したくありません。
A)Tk' 'の複数のインスタンスを作成し、そしてb)のhttpが表示されません:// effbot.org/tkinterbook/tkinter-dialog-windows.htm –
'command ='は関数名(コールバック)を期待しています - それは '()'なしを意味します。今度は 'popupBonusWindow.destroy()'とその結果を実行します - 恐らく 'None' - ' command = 'に代入します – furas