每当我运行程序时,都会弹出窗口,我会像平常一样在其中输入信息,当我按下下一个按钮时,窗口会像预期的那样退出,但随后会再次弹出相同的窗口。如果我在第二个窗口上按“下一步”,则该窗口将永久退出,并且不会弹出另一个窗口。我该如何解决这个问题,以便该窗口只弹出一次。我也不想将
def receive_credentials
放在自己的班级中。
from ApiCredentialsWindow import ApiCredentialsWindow
def receive_credentials(get_client_id, get_client_secret):
global CLIENT_ID
global CLIENT_SECRET
CLIENT_ID = get_client_id
CLIENT_SECRET = get_client_secret
print(CLIENT_ID)
print(CLIENT_SECRET)
credentials_window = ApiCredentialsWindow(receive_credentials)
import tkinter as tk
from tkinter import ttk
import webbrowser
class ApiCredentialsWindow:
def __init__(self, receive_credentials):
self.receive_credentials = receive_credentials
self.window = tk.Tk()
self.window_style = ttk.Style(self.window)
self.window.tk.call("source", "forest-dark.tcl")
self.window_style.theme_use("forest-dark")
self.window.option_add("*tearOff", False)
window_width = 375
window_height = 320
screen_width = self.window.winfo_screenwidth()
screen_height = self.window.winfo_screenheight()
window_position_x = (screen_width // 2) - (window_width // 2)
window_position_y = (screen_height // 2) - (window_height // 2)
self.window.geometry(f"{window_width}x{window_height}+{window_position_x}+{window_position_y}")
client_id_label = tk.Label(self.window, text="Client ID", font=("Segoe UI", 11), background=dark_gray_color)
client_id_label.pack(pady=(10, 0))
self.client_id_entry = ttk.Entry(self.window, width=30)
self.client_id_entry.pack(pady=(0, 10))
client_secret_label = tk.Label(self.window, text="Client secret:", font=("Segoe UI", 11), background=dark_gray_color)
client_secret_label.pack(pady=(10, 0))
self.client_secret_entry = ttk.Entry(self.window, width=30)
self.client_secret_entry.pack(pady=(0, 10))
next_button = ttk.Button(self.window, text="Next", style="Accent.TButton", command=self.get_credentials)
next_button.pack(pady=(15, 0))
self.window.mainloop()
def get_credentials(self):
get_client_id = self.client_id_entry.get()
get_client_secret = self.client_secret_entry.get()
self.receive_credentials(get_client_id, get_client_secret)
self.window.destroy()
所以我刚刚想通了。我正在使用 Flask,由于某种原因,当使用
app.run(debug=True)
而不是 app.run(debug=False)
时,会出现此问题。如果我将其设置为 false,则该窗口会弹出一次,但如果我将其设置为 True,则该窗口会弹出两次。如果有人知道为什么会发生这种情况,请告诉我。