在這個MainFrame類中,我有4個按鈕,每次點擊時都會在新窗口中導入一個類(除了更新)。我可以單擊每個按鈕一次,但如果我嘗試再次單擊一個按鈕,則不會彈出新窗口,也不會出現任何內容。爲什麼每個按鈕只能工作一次?Tkinter按鈕只能工作一次
from tkinter import *
import tkinter.messagebox as tm
import Users
import re
import sqlite3
db = sqlite3.connect('game nebula.db')
c = db.cursor()
class MainFrame(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.master = master
self.mainUI()
def mainUI(self):
self.master.title("Games Nebula")
self.pack(fill=BOTH, expand=True)
frame1 = Frame(self)
frame1.pack(fill=X)
frame2 = Frame(self)
frame2.pack(fill=X)
frame3 = Frame(self)
frame3.pack(fill=X)
self.label_1 = Label(frame1, text="Welcome to Games Nebula!", fg='green', relief='groove', width='40')
self.label_1.pack(side=TOP, padx=5, pady=5)
self.searchbtn = Button(frame2, text="Browse Games", fg='green', command = self._search_btn_clicked)
self.searchbtn.pack(side=LEFT, padx=25, pady=10)
self.addbtn = Button(frame2, text="Add games", fg='green', command=self._addbtn_btn_clicked)
self.addbtn.pack(side=RIGHT, padx=25, pady=10)
self.updatebtn = Button(frame3, text="Update", fg='green', command=self._update_btn_clicked)
self.updatebtn.pack(side=LEFT, padx=40, pady=10)
self.deletebtn = Button(frame3, text="Delete Games", fg='green', command=self._delete_btn_clicked)
self.deletebtn.pack(side=RIGHT, padx=25, pady=10)
def _search_btn_clicked(self):
print("Searching")
import GameSearch
def _addbtn_btn_clicked(self):
import Add
def _update_btn_clicked(self):
print("Updating")
def _delete_btn_clicked(self):
import Delete
root = Tk()
root.geometry("300x200+300+300")
lf = MainFrame(root)
root.mainloop()