def __init__(self): club_dic = load_info(FILENAME) self.main_window = tkinter.Tk(className="社團資訊系統") self.main_window.geometry('+800+300') self.top_frame = tkinter.Frame(self.main_window) self.mid_frame = tkinter.Frame(self.main_window) self.bottom_frame = tkinter.Frame(self.main_window) self.prompt_label = tkinter.Label(self.top_frame, text='選擇一個社團:') self.prompt_label.grid(padx=5, pady=5) for key in club_dic: self.key = tkinter.Button(self.mid_frame, text=club_dic[key][0], command=partial(self.m, key)) self.key.grid(padx=2, pady=2) self.quit_button = tkinter.Button(self.bottom_frame, text='結束', command=self.main_window.destroy) self.quit_button.grid(padx=5, pady=5) self.top_frame.grid(padx=5, pady=5) self.mid_frame.grid(padx=5, pady=5) self.bottom_frame.grid(padx=5, pady=5) tkinter.mainloop()
def showall(self): club_dic = load_info(FILENAME) name_lst = [] for code in club_dic: text = code + ' ' + club_dic[code][0] print(text) name_lst.append(text) tkinter.messagebox.showinfo(title='所有社團', message=name_lst)
def m(self, key): FILENAME = 'ClubInfo.dat' club_dic = load_info(FILENAME) print(club_dic[key][0]) tkinter.messagebox.showinfo('社團資訊', '社團名稱:' + club_dic[key][0] + '\n' + \ '社團人數:' + club_dic[key][2] + '\n' + \ '社團性質:' + club_dic[key][1] + '\n' + \ '社課時間:' + club_dic[key][3] + '\n' + \ '社辦:' + club_dic[key][4] + '\n' + \ '介紹:' + club_dic[key][5])
def delete(self): club_dic = load_info(FILENAME) code = self.entry.get() if code in club_dic: del club_dic[code] tkinter.messagebox.showinfo(title='完成', message='已刪除') save_info(FILENAME, club_dic) else: tkinter.messagebox.showinfo(title='注意', message='該社團不存在')
def login(self): code = self.entry.get() self.window.destroy() club_dic = load_info(FILENAME) if code in club_dic: ClubInfoGUI(code) else: tkinter.messagebox.showerror(title='錯誤', message='代號錯誤!') LoginGUI()
def add_club(self): # Get the data. club_dic = load_info(FILENAME) code = self.entry1.get() name = self.entry2.get() kind = self.entry3.get() num = self.entry4.get() time = self.entry5.get() loca = self.entry6.get() intro = self.entry7.get(1.0, tkinter.END) club_dic[code] = (name, kind, num, time, loca, intro) save_info(FILENAME, club_dic) self.window.destroy()
import tkinter import tkinter.messagebox from load_save import load_info from functools import partial FILENAME = 'ClubInfo.dat' club_dic = load_info(FILENAME) class Choose_clubGUI: def __init__(self): club_dic = load_info(FILENAME) self.main_window = tkinter.Tk(className="社團資訊系統") self.main_window.geometry('+800+300') self.top_frame = tkinter.Frame(self.main_window) self.mid_frame = tkinter.Frame(self.main_window) self.bottom_frame = tkinter.Frame(self.main_window) self.prompt_label = tkinter.Label(self.top_frame, text='選擇一個社團:') self.prompt_label.grid(padx=5, pady=5) for key in club_dic: self.key = tkinter.Button(self.mid_frame, text=club_dic[key][0], command=partial(self.m, key)) self.key.grid(padx=2, pady=2)
def ClubInfoGUI(code): club_dic = load_info(FILENAME) # Create window window = tkinter.Tk(className="社團資訊系統") window.geometry('+800+300') # Create data label1 = tkinter.Label(window, text='代號:') label1_1 = tkinter.Label(window, width=15, text=code) label2 = tkinter.Label(window, text='名稱:') entry2 = tkinter.Entry(window, width=15) entry2.insert(tkinter.END, club_dic[code][0]) print(club_dic[code][0]) label3 = tkinter.Label(window, text='性質:') entry3 = tkinter.Entry(window, width=15) entry3.insert(tkinter.END, club_dic[code][1]) print(club_dic[code][1]) print(club_dic[code]) label4 = tkinter.Label(window, text='人數:') entry4 = tkinter.Entry(window, width=15) entry4.insert(tkinter.END, club_dic[code][2]) print(club_dic[code][2]) label5 = tkinter.Label(window, text='社課時間:') entry5 = tkinter.Entry(window, width=15) entry5.insert(tkinter.END, club_dic[code][3]) print(club_dic[code][3]) label6 = tkinter.Label(window, text='社辦:') entry6 = tkinter.Entry(window, width=15) entry6.insert(tkinter.END, club_dic[code][4]) print(club_dic[code][4]) label7 = tkinter.Label(window, text='介紹:') entry7 = tkinter.Text(window, width=20) entry7.insert(1.0, club_dic[code][5]) # 排位置 label1.grid(row=1, column=1, sticky="E") label1_1.grid(row=1, column=2, padx=5, pady=5) label2.grid(row=2, column=1, sticky="E") entry2.grid(row=2, column=2, padx=5, pady=5) label3.grid(row=3, column=1, sticky="E") entry3.grid(row=3, column=2, padx=5, pady=5) label4.grid(row=4, column=1, sticky="E") entry4.grid(row=4, column=2, padx=5, pady=5) label5.grid(row=5, column=1, sticky="E") entry5.grid(row=5, column=2, padx=5, pady=5) label6.grid(row=6, column=1, sticky="E") entry6.grid(row=6, column=2, padx=5, pady=5) label7.grid(row=7, column=1, sticky="E") entry7.grid(row=7, column=2, padx=5, pady=5) # Create buttons button1 = tkinter.Button(window, text='修改', command=partial(save_edit, club_dic, code, entry2, entry3, entry4, entry5, entry6, entry7)) button2 = tkinter.Button(window, text='關閉', command=window.destroy) button1.grid(row=8, padx=5, pady=5, column=2, sticky="E") button2.grid(row=8, padx=5, pady=5, column=1, sticky="E") tkinter.mainloop()