[英]Problem with refreshing the content with python Tkinter , sqlite3
因此,我正在構建一個包含 5 個頁面(登錄、注冊、歡迎、text_writting、archived_text)的便箋應用程序,該應用程序可以容納多個用戶,並且每個用戶都有自己的便箋存儲在數據庫中,當我與用戶斷開連接並且我想切換到另一個用戶它保留舊用戶信息而不刷新並顯示新用戶信息,它僅在我關閉應用程序並重新打開它時顯示 Plus -> 當我檢查數據庫時一切順利,更新日期問題只是在圖形用戶界面中
class main_app(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
data_baseconnect=sqlite3.connect('NOTES_DB.db')
data_cursor=data_baseconnect.cursor()
data_cursor.execute('SELECT current_state from LOGINS_STATE')
data_baseconnect.commit()
Current_person_state = data_cursor.fetchall()
for frame_class in (Login_page,Register_page, Welcoming_page,notes_page1,notes_page2):
frame = frame_class(container, self)
self.frames[frame_class] = frame
frame.grid(row=0, column=0, sticky="nsew")
if Current_person_state[0][0]==0:
self.show_frame(Login_page)
else :
self.update()
self.show_frame(Welcoming_page)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
#Login page
class Login_page(tk.Frame):
def __init__(self, parent, controller):
def user_connect() :
#Login_page_User_name_Entry is an entry when the user type the new person he want to connect
#through // this user is already in the data base
global Current_userV2
database_connection=sqlite3.connect('NOTES_DB.db')
data_currsor=database_connection.cursor()
Login_page_Error_connect.config(text='')
Current_userV2=str(Login_page_User_name_Entry.get())
data_currsor.execute("UPDATE LOGINS_STATE SET current_user=(?),current_state=(?)",((str(Login_page_User_name_Entry.get())),('1')))
database_connection.commit()
controller.show_frame(Welcoming_page)
tk.Frame.__init__(self,parent,bg='#EDD01C')
Login_page_connect_button=Button(Login_page_frame,text="Connect",width=20,height=2,bg='green',command=user_connect)
Login_page_connect_button.place(x=80,y=300)
.....
class Welcoming_page(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent,bg='#EDD01C')
def Leave_button() :
global Current_userV2
database_connect=sqlite3.connect('NOTES_DB.db')
data_cursor=database_connect.cursor()
data_cursor.execute('UPDATE LOGINS_STATE set current_user=NULL,current_state=0')
database_connect.commit()
Current_userV2=''
controller.show_frame(Login_page)
disconnect_button=Button(self,text="Disconnect",bg='red',command=Leave_button,font=('arial',15))
disconnect_button.place(x=350,y=500)
....
我想出了這里的方法:只需在 main_app class 中進行更改:
class main_app(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.container = tk.Frame(self)
self.container.pack(fill="both", expand=True)
self.current_frame = None
data_baseconnect=sqlite3.connect('NOTES_DB.db')
data_cursor=data_baseconnect.cursor()
data_cursor.execute('SELECT current_state from LOGINS_STATE')
data_baseconnect.commit()
Current_person_state = data_cursor.fetchall()
if Current_person_state[0][0]==0:
self.show_frame(Login_page)
else :
self.show_frame(Welcoming_page)
def show_frame(self, new_frame_class):
if self.current_frame:
self.current_frame.destroy()
self.current_frame = new_frame_class(self.container, controller=self)
self.current_frame.pack(fill="both", expand=True)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.