| 1 | import tkinter as tk |
| 2 | |
| 3 | class MainApp(tk.Tk): |
| 4 | def __init__(self,keys_list,dictionary): |
| 5 | super().__init__() |
| 6 | self.geometry("350x350") |
| 7 | self.title("@MyApp") |
| 8 | self.configure(bg="#C2FCEE") |
| 9 | self.resizable(False,False) |
| 10 | self.scrollbar = tk.Scrollbar(orient='vertical',relief='groove') |
| 11 | self.keyslist = keys_list |
| 12 | self.dictionary = dictionary |
| 13 | self.setup() |
| 14 | |
| 15 | def setup(self): |
| 16 | self.widgets() |
| 17 | self.layouts() |
| 18 | self.show_keys(select_id=self.lists) |
| 19 | |
| 20 | def widgets(self): |
| 21 | self.lists = tk.Listbox(bg='#83FCE3',border=1,width=8,height=12,yscrollcommand=self.scrollbar.set) |
| 22 | for n,line in enumerate(self.keyslist): |
| 23 | self.lists.insert(n,line) |
| 24 | self.lists.bind("<<ListboxSelect>>",self.show_keys) |
| 25 | self.scrollbar.config(command = self.lists.yview) |
| 26 | |
| 27 | self.canvas = tk.Canvas(bg='#83FCE3',border=1,width=190,height=190,relief='groove') |
| 28 | |
| 29 | self.quit_btn = tk.Button(cursor='target',bg="#C2FCEE",text='quit',command=self.quit) |
| 30 | |
| 31 | # create a frame to align with the canvas widget |
| 32 | self.frame = tk.Frame(bg="#C2FCEE",width=180,height=180) |
| 33 | |
| 34 | self.btn1 = tk.Button(self.frame,cursor='target',bg="#C2FCEE",text='Pinyin',command=self.show_pinyin) |
| 35 | self.btn2 = tk.Button(self.frame,cursor='target',bg="#C2FCEE",text='Role',command=self.show_role) |
| 36 | self.btn3 = tk.Button(self.frame,cursor='target',bg="#C2FCEE",text='Definition',command=self.show_definition) |
| 37 | |
| 38 | self.label1 = tk.Label(self.frame,bg="#C2FCEE",text='',font=('Roboto','15')) |
| 39 | self.label2 = tk.Label(self.frame,bg="#C2FCEE",text='',font=('Roboto','15')) |
| 40 | self.label3 = tk.Label(self.frame,bg="#C2FCEE",text='',font=('Roboto','15')) |
| 41 | |
| 42 | def layouts(self): |
| 43 | |
| 44 | self.lists.grid(column=0,row=0,padx=15,pady=8) |
| 45 | self.scrollbar.grid(column=1,row=0,sticky="NS",pady=10) |
| 46 | self.canvas.grid(column=2,row=0,padx=15,pady=15,sticky='N') |
| 47 | self.quit_btn.grid(columnspan=1,row=1,pady=5,sticky='S') |
| 48 | self.frame.grid(column=2,row=1) |
| 49 | self.btn1.grid(column=2,row=1,pady=5,padx=5,ipadx=10) |
| 50 | self.btn2.grid(column=2,row=2,pady=5,padx=1,ipadx=14) |
| 51 | self.btn3.grid(column=2,row=3,pady=5,padx=5,ipadx=4) |
| 52 | self.label1.grid(column=3,row=1,pady=5,padx=20) |
| 53 | self.label2.grid(column=3,row=2,pady=5,padx=20) |
| 54 | self.label3.grid(column=3,row=3,pady=5,padx=20) |
| 55 | |
| 56 | def show_keys(self,select_id): |
| 57 | global select_keys |
| 58 | # get the indices from our sinographs list |
| 59 | select_id = self.lists.curselection() |
| 60 | keyslists = self.lists |