diff --git a/pythonProject/.idea/.gitignore b/pythonProject/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/pythonProject/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/pythonProject/.idea/encodings.xml b/pythonProject/.idea/encodings.xml deleted file mode 100644 index fa4a8c2..0000000 --- a/pythonProject/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/pythonProject/mysqlconnect.py b/pythonProject/mysqlconnect.py deleted file mode 100644 index b3591d2..0000000 --- a/pythonProject/mysqlconnect.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: gbk -*- -import pymysql -import pandas as pd -# -*- coding: -*- - - -db_config = { - 'host': 'localhost', - 'port': 3306, - 'user': 'root', - 'password': '21412030117', - 'database': 'word', - 'charset': 'utf8mb4', -} - - -try: - connection = pymysql.connect(**db_config) - cursor = connection.cursor() - extracted='words.csv' - data_to_insert= pd.read_csv(extracted) - - - for item in data_to_insert: - xuhao, neirong = item - insert_sql = "INSERT INTO word (xuhao, neirong) VALUES (%s, %s)" - cursor.execute(insert_sql, (xuhao, neirong)) - - - connection.commit() - print("数据插入成功!") -except Exception as e: - print(f"数据插入失败,错误信息:{e}") \ No newline at end of file diff --git a/pythonProject/test.py b/pythonProject/test.py deleted file mode 100644 index 681874e..0000000 --- a/pythonProject/test.py +++ /dev/null @@ -1,39 +0,0 @@ -import re -import csv -from bs4 import BeautifulSoup -import requests - -url = 'https://zhuanlan.zhihu.com/p/105570623' -response = requests.get(url) -soup = BeautifulSoup(response.text, 'html.parser') - -# 鍒濆鍖栨暟鎹垪琛紝鐢ㄤ簬瀛樻斁鎻愬彇鐨勪俊鎭 -data = [] - -# 鍋囪鎴戜滑瑕佹彁鍙栭〉闈笂鐨勬墍鏈夋钀芥枃鏈腑鏁板瓧鍔犲彞鍙峰悗闈㈢殑鍐呭 -paragraphs = soup.find_all('p') -for paragraph in paragraphs: - text = paragraph.get_text() - # 浣跨敤姝e垯琛ㄨ揪寮忓尮閰嶆暟瀛楀姞鍙ュ彿鍚庨潰鐨勫唴瀹 - matches = re.findall(r'\d+\.\s*(.*)', text) - for match in matches: - # 灏嗗尮閰嶅埌鐨勫唴瀹规坊鍔犲埌data鍒楄〃涓紝杩欓噷鍋囪搴忓彿鏄繛缁殑锛屼粠1寮濮嬮掑 - data.append([len(data)+1, match.strip()]) - -# 瀹氫箟CSV鏂囦欢鐨勫悕绉 -filename = 'extracted_data.csv' - -# 鍐欏叆CSV鏂囦欢 -with open(filename, 'w', newline='', encoding='utf-8') as csvfile: - csvwriter = csv.writer(csvfile) - # 鍐欏叆琛ㄥご - csvwriter.writerow(['搴忓彿', '鍐呭','']) - # 鍐欏叆鏁版嵁 - for row in data: - # 娉ㄦ剰锛屽師闂娌℃湁鏄庣‘"鍗曡瘝"鏉ユ簮锛岃繖閲屽亣璁炬瘡鏉℃暟鎹彧鏈夊簭鍙峰拰鍐呭涓ゅ垪 - csvwriter.writerow(row) - -print(f"鏁版嵁宸叉垚鍔熷啓鍏filename}") - - - diff --git a/pythonProject/test1.py b/pythonProject/test1.py deleted file mode 100644 index 291cf9f..0000000 --- a/pythonProject/test1.py +++ /dev/null @@ -1,39 +0,0 @@ -import tkinter as tk -from tkinter import messagebox -import csv - -class WordApp(tk.Tk): - def __init__(self): - super().__init__() - self.title("鍗曡瘝瀛︿範") - self.current_word_index = 0 - self.words = self._read_words_from_csv() # 纭繚鏂规硶鍚嶆纭笖瀹氫箟鍦ㄧ被鍐呴儴 - self.word_label = tk.Label(self, text="", font=("Helvetica", 20)) - self.word_label.pack(pady=20) - self.create_buttons() - - def _read_words_from_csv(self): # 鍋囪杩欎釜鏂规硶宸茶瀹氫箟鍦ㄨ繖閲 - words = [] - with open('words.csv', mode='r', encoding='utf-8') as file: - reader = csv.reader(file) - for row in reader: - words.append(row[1]) # 鍋囪鍗曡瘝鍦–SV鐨勭涓鍒 - return words - - def create_buttons(self): - self.know_button = tk.Button(self, text="璁よ瘑", command=self.show_next_word, width=10) - self.not_know_button = tk.Button(self, text="涓嶈璇", command=self.show_next_word, width=10) - self.know_button.pack(side=tk.LEFT, padx=10, pady=10) - self.not_know_button.pack(side=tk.RIGHT, padx=10, pady=10) - - def show_next_word(self): - if self.current_word_index < len(self.words): - self.word_label.config(text=self.words[self.current_word_index]) - self.current_word_index += 1 - else: - messagebox.showinfo("缁撴潫", "鎵鏈夊崟璇嶅凡瀛︿範瀹屾瘯锛") - self.destroy() - -if __name__ == "__main__": - app = WordApp() - app.mainloop() \ No newline at end of file diff --git a/pythonProject/word_database.db b/pythonProject/word_database.db deleted file mode 100644 index ae5a245..0000000 Binary files a/pythonProject/word_database.db and /dev/null differ diff --git a/pythonProject/words.csv b/pythonProject/words.csv deleted file mode 100644 index ef9aec4..0000000 --- a/pythonProject/words.csv +++ /dev/null @@ -1,71 +0,0 @@ -搴忓彿,鍐呭 -1,abandon vt.涓㈠純锛涙斁寮冿紝鎶涘純 -2,ability n.鑳藉姏锛涜兘鑰愶紝鏈 -3,abnormal a.涓嶆甯哥殑锛涘彉鎬佺殑 -4,aboard ad.鍦ㄨ埞(杞)涓婏紱涓婅埞 -5,abroad ad.(鍦)鍥藉锛涘埌澶 -6,absence n.缂哄腑锛屼笉鍦ㄥ満锛涚己涔 -7,absent a.涓嶅湪鍦虹殑锛涚己涔忕殑 -8,abstract a.鎶借薄鐨 n.鎽樿 -9,abundant a.涓板瘜鐨勶紱澶ч噺鐨 -10,abuse vt.婊ョ敤锛涜檺寰 n.婊ョ敤 -11,access n.鎺ヨ繎锛涢氶亾锛屽叆鍙 -12,accompany vt.闄即锛岄櫔鍚岋紱浼撮殢 -13,accomplish vt.杈惧埌(鐩殑)锛涘畬鎴 -14,account n.璁拌堪锛涜В閲婏紱甯愮洰 -15,accuse vt.鎸囪矗锛涘綊鍜庝簬 -16,accustom vt.浣夸範鎯 -17,accustomed a.鎯父鐨勶紱涔犳儻鐨 -18,achieve vt.瀹屾垚锛屽疄鐜帮紱杈惧埌 -19,achievement n.瀹屾垚锛涙垚灏憋紝鎴愮哗 -20,acquaintance n.璁よ瘑锛涗簡瑙o紱鐔熶汉 -21,act vi.琛屽姩锛涜鏁 n.琛屼负 -22,action n.琛屽姩锛涗綔鐢紱鍔熻兘 -23,active a.娲昏穬鐨勶紱绉瀬鐨 -24,activity n.娲诲姩锛涙椿鍔涳紱琛屽姩 -25,actress n.濂虫紨鍛 -26,actually ad.瀹為檯涓婏紱绔熺劧 -27,acute a.灏栫殑锛岄攼鐨勶紱鏁忛攼鐨 -28,add vt.娣诲姞锛岄檮鍔狅紝鎺哄姞 -29,addition n.鍔狅紝鍔犳硶锛涢檮鍔犵墿 -30,additional a.闄勫姞鐨勶紝杩藉姞鐨 -31,address n.鍦板潃锛涙紨璇达紱璋堝悙 -32,adjust vt.璋冩暣锛岃皟鑺傦紱鏍℃ -33,administration n.绠$悊锛涚鐞嗛儴闂 -34,admire vt.閽︿僵锛岀尽鎱曪紝璧炶祻 -35,admission n.鍏佽杩涘叆锛涙壙璁 -36,admit vt.鎵胯锛涘噯璁糕﹁繘鍏 -37,advance vi.鍓嶈繘锛涙彁楂 n.杩涘睍 -38,advanced a.鍏堣繘鐨勶紱楂樼骇鐨 -39,advantage n.浼樼偣锛屼紭鍔匡紱濂藉 -40,adventure n.鍐掗櫓锛涙儕闄╂椿鍔 -41,adult -42,advertisement n.骞垮憡锛涚櫥骞垮憡 -43,advisable n.鏄庢櫤鐨勶紱鍙彇鐨 -44,advise vt.鍔濆憡锛涘缓璁紱閫氱煡 -45,affect vt.褰卞搷锛涙劅鍔 -46,affection n.鎱堢埍锛岀埍锛涚埍鎱 -47,afford vt.鎷呰礋寰楄捣鈥︼紱鎻愪緵 -48,aggressive a.渚电暐鐨勶紱濂芥枟鐨 -49,agony n.鏋佸害鐥涜嫤 -50,agreement n.鍗忓畾锛屽崗璁紱鍚屾剰 -51,agriculture n.鍐滀笟锛屽啘鑹猴紱鍐滃 -52,aid n.甯姪锛屾晳鎶わ紱鍔╂墜 -53,airline -54,alphabet n.瀛楁瘝琛紝瀛楁瘝绯荤粺 -55,alter vt.鏀瑰彉锛屽彉鏇达紱鏀瑰仛 -56,alternative n.鏇挎崲鐗╋紱鍙栬垗锛屾妷鎷 -57,although conj.灏界锛岃櫧鐒 -58,altitude n.楂橈紝楂樺害锛涢珮澶 -59,altogether ad.瀹屽叏锛涙昏岃█涔 -60,amaze vt.浣挎儕濂囷紝浣挎儕鎰 -61,ambition n.闆勫績锛屾姳璐燂紝閲庡績 -62,ambitious -63,ambulance n.鏁戞姢杞︼紱閲庢垬鍖婚櫌 -64,amplify vt.鏀惧ぇ锛屽寮猴紱鎵╁ぇ -65,amuse vt.閫椻︿箰锛涚粰鈥﹀ū涔 -66,angel n.澶╀娇锛岀宸紝瀹夌惇鍎 -67,anger n.鎬掞紝鎰ゆ vt.浣垮彂鎬 -68,angle n.瑙掞紝瑙掑害 -69,ankle n.韪濓紝韪濊妭閮 -70,a diff --git a/pythonProject1/.idea/.gitignore b/pythonProject1/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/pythonProject1/.idea/.gitignore @@ -0,0 +1,3 @@ +# 榛樿蹇界暐鐨勬枃浠 +/shelf/ +/workspace.xml diff --git a/pythonProject/.idea/inspectionProfiles/profiles_settings.xml b/pythonProject1/.idea/inspectionProfiles/profiles_settings.xml similarity index 100% rename from pythonProject/.idea/inspectionProfiles/profiles_settings.xml rename to pythonProject1/.idea/inspectionProfiles/profiles_settings.xml diff --git a/pythonProject/.idea/misc.xml b/pythonProject1/.idea/misc.xml similarity index 54% rename from pythonProject/.idea/misc.xml rename to pythonProject1/.idea/misc.xml index 2a01189..a50ac5b 100644 --- a/pythonProject/.idea/misc.xml +++ b/pythonProject1/.idea/misc.xml @@ -1,7 +1,7 @@ - - + \ No newline at end of file diff --git a/pythonProject/.idea/modules.xml b/pythonProject1/.idea/modules.xml similarity index 52% rename from pythonProject/.idea/modules.xml rename to pythonProject1/.idea/modules.xml index e15ec35..fdd8fdf 100644 --- a/pythonProject/.idea/modules.xml +++ b/pythonProject1/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/pythonProject/.idea/pythonProject.iml b/pythonProject1/.idea/pythonProject1.iml similarity index 61% rename from pythonProject/.idea/pythonProject.iml rename to pythonProject1/.idea/pythonProject1.iml index 177f301..2c80e12 100644 --- a/pythonProject/.idea/pythonProject.iml +++ b/pythonProject1/.idea/pythonProject1.iml @@ -2,9 +2,9 @@ - + - + \ No newline at end of file diff --git a/pythonProject1/test.py b/pythonProject1/test.py new file mode 100644 index 0000000..a474602 --- /dev/null +++ b/pythonProject1/test.py @@ -0,0 +1,35 @@ +import pymysql + +# 鏁版嵁搴撹繛鎺ュ弬鏁 +db_config = { + 'host': 'localhost', # 鏁版嵁搴撳湴鍧锛岄粯璁ocalhost + 'port': 3306, # 鏁版嵁搴撶鍙o紝榛樿3306 + 'user': 'root', # 鏁版嵁搴撶敤鎴峰悕 + 'password': '21412030117', # 鏁版嵁搴撳瘑鐮 + 'database': 'word', # 瑕佽繛鎺ョ殑鏁版嵁搴撳悕 + 'charset': 'utf8mb4', # 瀛楃缂栫爜锛屾帹鑽愪娇鐢╱tf8mb4鏀寔鏇村瀛楃闆 +} + +# 灏濊瘯寤虹珛杩炴帴 +try: + connection = pymysql.connect(**db_config) + print("杩炴帴MySQL鏁版嵁搴撴垚鍔") + + # 鍒涘缓娓告爣 + cursor = connection.cursor() + + # 鎵цSQL鏌ヨ + sql_query = "SELECT * FROM words" + cursor.execute(sql_query) + + # 鑾峰彇鏌ヨ缁撴灉 + results = cursor.fetchall() + for row in results: + print(row) + + # 鍏抽棴娓告爣鍜岃繛鎺 + cursor.close() + connection.close() + +except pymysql.MySQLError as e: + print(f"杩炴帴鏁版嵁搴撴椂鍙戠敓閿欒: {e}") \ No newline at end of file diff --git a/pythonProject1/test1.py b/pythonProject1/test1.py new file mode 100644 index 0000000..bd4fa89 --- /dev/null +++ b/pythonProject1/test1.py @@ -0,0 +1,260 @@ +import tkinter as tk +from tkinter import messagebox +import random +import pymysql + +class LoginPage(tk.Toplevel): + def __init__(self, master=None): + super().__init__(master) + self.title("鐧诲綍") + self.geometry("200x200") + + self.username_var = tk.StringVar() + self.password_var = tk.StringVar() + + tk.Label(self, text="鐢ㄦ埛鍚:").pack() + tk.Entry(self, textvariable=self.username_var).pack() + + tk.Label(self, text="瀵嗙爜:").pack() + tk.Entry(self, show="*", textvariable=self.password_var).pack() + + tk.Button(self, text="鐧诲綍", command=self.login).pack(pady=10) + + def login(self): + username = self.username_var.get() + password = self.password_var.get() + if username == "a" and password == "123456": + self.master.destroy() # 鍏抽棴涓荤獥鍙o紙濡傛灉鏈夛級锛岃繖閲屽亣璁剧洿鎺ュ叧闂嚜韬篃琛岋紝鍙栧喅浜庡疄闄呯粨鏋 + MainApp().mainloop() # 鐧诲綍鎴愬姛鍚庡疄渚嬪寲MainApp骞跺惎鍔ㄥ叾涓诲惊鐜 + else: + messagebox.showerror("閿欒", "鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒锛") # 鐧诲綍澶辫触锛屼繚鎸佺櫥褰曠晫闈㈡墦寮渚涚敤鎴烽噸璇 + + + +class MainApp(tk.Tk): + def __init__(self): + super().__init__() + self.title("鍗曡瘝瀛︿範") + self.geometry("200x200") + + # 鍒涘缓涓変釜鎸夐挳 + tk.Button(self, text="瀛︿範鏂板崟璇", command=self.open_window1).pack(fill=tk.X, padx=10, pady=5) + tk.Button(self, text="澶嶄範鍗曡瘝", command=self.open_window2).pack(fill=tk.X, padx=10, pady=5) + tk.Button(self, text="鏄撻敊鍗曡瘝鏌ョ湅", command=self.open_window3).pack(fill=tk.X, padx=10, pady=5) + + def open_window1(self): + Window1(self) + + def open_window2(self): + Window2(self) + + def open_window3(self): + Window3(self) + + +class Window1(tk.Toplevel): + def __init__(self, master): + super().__init__(master) + self.title("鍗曡瘝瀛︿範鐣岄潰") + + # 鍒濆鍖朚ySQL鏁版嵁搴撹繛鎺 + self.conn = pymysql.connect( + host="localhost", # MySQL鏈嶅姟鍣ㄥ湴鍧 + user="root", # 鏁版嵁搴撶敤鎴峰悕 + password="21412030117", # 鏁版嵁搴撳瘑鐮 + database="word", # 鏁版嵁搴撳悕 + charset='utf8mb4', # 瀛楃缂栫爜锛屾牴鎹渶瑕佽皟鏁 + cursorclass=pymysql.cursors.DictCursor # 浣跨敤瀛楀吀娓告爣锛屾柟渚块氳繃鍒楀悕璁块棶鏁版嵁 + ) + + self.cursor = self.conn.cursor() + + self.word_frame = tk.Frame(self) + self.word_frame.pack(padx=10, pady=10) + + self.next_button = tk.Button(self, text="涓嬩竴涓崟璇", command=self.show_next_word) + self.next_button.pack(side=tk.RIGHT, padx=5, pady=5) + self.prev_button = tk.Button(self, text="涓婁竴涓崟璇") # 瀹炵幇閫昏緫寰呰ˉ鍏 + self.prev_button.pack(side=tk.LEFT, padx=5, pady=5) + + self.show_next_word() # 鍒濆鏄剧ず涓涓崟璇 + + def show_next_word(self): + # 鏌ヨ骞惰幏鍙栦竴涓湭瀛︿範鐨勫崟璇 + query = ("SELECT word, meaning FROM words WHERE learned = 0 ORDER BY RAND() LIMIT 1") + self.cursor.execute(query) + word_row = self.cursor.fetchone() + if word_row: + word, meaning = word_row['word'], word_row['meaning'] # 浣跨敤瀛楀吀璁块棶鍒 + self.display_word(word, meaning) + # 鏍囪璇ュ崟璇嶄负宸插涔 + self.mark_word_as_learned(word) + else: + messagebox.showinfo("鎻愮ず", "鎵鏈夊崟璇嶉兘宸插涔犺繃锛") + + def display_word(self, word, meaning): + """鏄剧ず鍗曡瘝鍙婂叾鎰忎箟""" + for widget in self.word_frame.winfo_children(): + widget.destroy() + + tk.Label(self.word_frame, text=f"鍗曡瘝: {word}").pack(anchor=tk.W) + tk.Label(self.word_frame, text=f"鎰忎箟: {meaning}").pack(anchor=tk.W) + + def mark_word_as_learned(self, word): + """灏嗗崟璇嶆爣璁颁负宸插涔""" + update_query = ("UPDATE words SET learned = 1 WHERE word = %s") + self.cursor.execute(update_query, (word,)) + self.conn.commit() + + +class Window2(tk.Toplevel): + def __init__(self, master): + super().__init__(master) + self.title("鍗曡瘝鎷煎啓娴嬭瘯") + self.conn = pymysql.connect( + host="localhost", + user="root", + password="21412030117", + database="word", + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor + ) + self.cursor = self.conn.cursor() + self.setup_ui() + self.protocol("WM_DELETE_WINDOW", self.on_closing) + self.word_error_count = {} # 鏂板锛氬瓨鍌ㄥ崟璇嶉敊璇鏁扮殑瀛楀吀 + + def setup_ui(self): + self.word_label = tk.Label(self, text="", font=("Arial", 16)) + self.word_label.pack(pady=10) + + self.entry_var = tk.StringVar() + self.user_entry = tk.Entry(self, textvariable=self.entry_var, font=("Arial", 14)) + self.user_entry.pack(ipady=5, pady=10) + + self.result_label = tk.Label(self, text="", fg="black", font=("Arial", 12)) + self.result_label.pack(pady=5) + + self.next_button = tk.Button(self, text="涓嬩竴涓崟璇", state=tk.DISABLED, command=self.show_next_word) + self.next_button.pack(pady=10) + + self.show_next_word() # 鍒濆鍖栨樉绀轰竴涓崟璇 + + def show_next_word(self): + self.next_button.config(state=tk.DISABLED) # 绂佺敤鎸夐挳闃叉閲嶅鐐瑰嚮 + self.cursor.execute("SELECT `word`, `meaning` FROM `words` WHERE `learned` = 1 ORDER BY RAND() LIMIT 1") + word_row = self.cursor.fetchone() + if word_row: + self.current_word = word_row['word'] + self.current_meaning = word_row['meaning'] + self.word_label.config(text=f"鍚箟锛歿self.current_meaning}") + self.entry_var.set("") # 娓呯┖杈撳叆妗 + self.result_label.config(text="") + self.user_entry.bind("", lambda event: self.check_spelling()) # 缁戝畾鍥炶溅閿鏌ユ嫾鍐 + else: + messagebox.showinfo("鎻愮ず", "娌℃湁鏇村宸插涔犵殑鍗曡瘝鍙緵娴嬭瘯锛") + self.destroy() + + def check_spelling(self): + user_input = self.entry_var.get().strip().lower() + if user_input == self.current_word.lower(): + self.result_label.config(text="姝g‘!", fg="green") + self.next_button.config(state=tk.NORMAL) # 姝g‘鍚庡惎鐢ㄦ寜閽 + self.entry_var.set("") # 娓呯┖杈撳叆妗 + self.result_label.config(text="") + self.word_error_count[self.current_word] = 0 # 閲嶇疆閿欒璁℃暟 + else: + self.result_label.config(text=f"閿欒锛", fg="red") + self.user_entry.delete(0, tk.END) # 娓呯┖杈撳叆妗嗗苟鏄剧ず姝g‘绛旀 + self.user_entry.insert(0, self.current_word) # 鍦ㄨ緭鍏ユ涓樉绀烘纭瓟妗 + self.user_entry.config(fg="red") # 灏嗚緭鍏ユ鏂囧瓧棰滆壊璁句负绾㈣壊 + self.user_entry.unbind("") # 閬垮厤鍦ㄦ樉绀虹瓟妗堟椂鍝嶅簲鍥炶溅閿 + self.user_entry.bind("", lambda event: self.clear_and_rebind(event)) # 缁戝畾宸﹂敭鐐瑰嚮浜嬩欢浠ユ竻闄ゅ苟閲嶆柊缁戝畾 + + # 鏇存柊閿欒璁℃暟 + if self.current_word in self.word_error_count: + self.word_error_count[self.current_word] += 1 + else: + self.word_error_count[self.current_word] = 1 + + # 杈惧埌閿欒娆℃暟闄愬埗鏃舵洿鏂版暟鎹簱 + if self.word_error_count[self.current_word] > 3: + self.update_easily_mistaken_in_db() + + def update_easily_mistaken_in_db(self): + """鏇存柊鏁版嵁搴撲腑鍗曡瘝鐨別asily_mistaken瀛楁涓1""" + try: + update_query = ( + "UPDATE `words` SET `easily_mistaken` = 1 " + "WHERE `word` = %s AND `easily_mistaken` != 1" + ) + self.cursor.execute(update_query, (self.current_word,)) + self.conn.commit() + print(f"鍗曡瘝'{self.current_word}'鏍囪涓烘槗閿欏崟璇嶃") + except Exception as e: + print(f"鏇存柊鏁版嵁搴撴椂鍑洪敊锛歿e}") + def clear_and_rebind(self, event): + self.user_entry.delete(0, tk.END) # 娓呯┖杈撳叆妗 + self.user_entry.config(fg="black") # 閲嶇疆杈撳叆妗嗘枃瀛楅鑹蹭负榛戣壊 + self.user_entry.bind("", lambda event: self.check_spelling()) # 閲嶆柊缁戝畾鍥炶溅閿簨浠 + + def on_closing(self): + self.conn.close() + self.destroy() + + +class Window3(tk.Toplevel): + def __init__(self, master): + super().__init__(master) + self.title("鏄撻敊鍗曡瘝澶嶄範") + self.conn = pymysql.connect( + host="localhost", + user="root", + password="21412030117", + database="word", + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor + ) + self.cursor = self.conn.cursor() + self.setup_ui() + self.show_next_mistaken_word() # 鍒濆鍖栨樉绀轰竴涓槗閿欏崟璇 + + def setup_ui(self): + self.word_label = tk.Label(self, text="", font=("Arial", 16)) + self.word_label.pack(pady=10) + + self.next_button = tk.Button(self, text="涓嬩竴涓崟璇", command=self.show_next_mistaken_word) + self.next_button.pack(pady=10) + + def show_next_mistaken_word(self): + self.cursor.execute("SELECT `word`, `meaning` FROM `words` WHERE `easily_mistaken` = 1 ORDER BY RAND() LIMIT 1") + word_row = self.cursor.fetchone() + if word_row: + self.current_word = word_row['word'] + self.current_meaning = word_row['meaning'] + self.word_label.config(text=f"鍚箟锛歿self.current_meaning}") + else: + messagebox.showinfo("鎻愮ず", "娌℃湁鏇村鏄撻敊鍗曡瘝鍙緵澶嶄範锛") + self.destroy() + + def on_closing(self): + self.conn.close() + self.destroy() + + def protocol(self, event): + self.on_closing() + + +# 鍦ㄥ垱寤篧indow3瀹炰緥鐨勫湴鏂圭‘淇濊皟鐢╬rotocol鏂规硶缁戝畾鍏抽棴浜嬩欢 +#window3 = Window3(root) +#window3.protocol("WM_DELETE_WINDOW", window3.on_closing) + +def start_application(): + root = tk.Tk() + root.withdraw() # 闅愯棌鏍圭獥鍙o紝鍥犱负鎴戜滑鐩存帴浣跨敤Toplevel浣滀负鐧诲綍鐣岄潰 + LoginPage(master=root) # 灏嗕富绐楀彛浣滀负master浼犵粰LoginPage锛屼究浜庡悗缁搷浣 + root.mainloop() # 涓诲惊鐜湪姝ゅ惎鍔紝鎺у埗鏁翠釜搴旂敤鐨勭敓鍛藉懆鏈 + + +if __name__ == "__main__": + start_application() \ No newline at end of file