def build_notebook(self, top): mono_font = self.get_mono_font() nb = tix.NoteBook(top) nb.add("item_page", label="items", raisecmd=lambda pg="item": self.ev_page(pg)) fr = tix.Frame(nb.subwidget("item_page")) self.item_fmt = "{:15} {:15} {:10} ${:<8} {:12}" tix.Label(fr, font=mono_font, text=self.item_fmt.format("Name", "Description", "Owner", "Price", "Condition")).pack(anchor="w") # 使用tix.ScrolledListBox而不是tix.ScrolledText小部件。使用ScrolledListBox小部件可以更加容易地选择行。 slb = tix.ScrolledListBox(fr, width=500, height=200) slb.pack(fill="both", expand=True) fr.pack(fill="both", expand=True) self.item_list = slb.subwidget("listbox") self.item_list.configure(font=mono_font, bg="white") # 使用bind()方法将鼠标左键双击链接到适当的编辑事件处理程序上。除了处理默认小部件的命令,bind()机制可以处理任意事件。 # 不同的是,回调函数必须接受一个事件参数并为参数设置了默认值None。这样普通的回调机制以及双击链接也可以使用它 self.item_list.bind("<Double-1>", self.ev_edit_item) # 事件处理程序都是自解释型的。在选中新的notebook页时,就会触发ev_page()处理程序。它只是为活动页面启动对应的菜单。 nb.add("member_page", label="members", raisecmd=lambda pg="member": self.ev_page(pg)) fr = tix.Frame(nb.subwidget("member_page")) self.member_fmt = "{:<15} {:<40}" tix.Label(fr, font=mono_font, text=self.member_fmt.format( "Name", "Email Address")).pack(anchor="w") slb = tix.ScrolledListBox(fr, width=40, height=20) slb.pack(fill="both", expand=True) fr.pack(fill="both", expand=True) self.member_list = slb.subwidget("listbox") self.member_list.configure(font=mono_font, bg="white") self.member_list.bind("<Double-1>", self.ev_edit_member) return nb
def __init__(self, root): super().__init__(root) self.root = root self._data = None self.scrolled_listbox = tix.ScrolledListBox(self, width=0, height=0) self.listbox = self.scrolled_listbox.listbox self.listbox.bind('<<ListboxSelect>>', self.select_callback) self.scrolled_listbox.grid(row=0, column=0, sticky='nsew') self.rowconfigure(0, weight=1) self.columnconfigure(0, weight=1)
def buildNoteBook(self, top): mono_font = self.getMonoFont() nb = tix.NoteBook(top) nb.add("itemPage", label="Items", raisecmd=lambda pg="item": self.evPage(pg)) fr = tix.Frame(nb.subwidget("itemPage")) self.itemFmt = "{:15} {:15} {:10} ${:<8} {:12}" tix.Label(fr, font=mono_font, text=self.itemFmt.format("Name", "Description", "Owner", "Price", "Condition")).pack(anchor='w') slb = tix.ScrolledListBox(fr, width=500, height=200) slb.pack(fill='both', expand=True) fr.pack(fill='both', expand=True) self.itemList = slb.subwidget("listbox") self.itemList.configure(font=mono_font, bg='white') self.itemList.bind('<Double-1>', self.evEditItem) nb.add("memberPage", label="Members", raisecmd=lambda pg="member": self.evPage(pg)) fr = tix.Frame(nb.subwidget("memberPage")) self.memberFmt = "{:<15} {:<40}" tix.Label(fr, font=mono_font, text=self.memberFmt.format("Name", "Email Address")).pack(anchor='w') slb = tix.ScrolledListBox(fr, width=40, height=20) slb.pack(fill='both', expand=True) fr.pack(fill='both', expand=True) self.memberList = slb.subwidget("listbox") self.memberList.configure(font=mono_font, bg='white') self.memberList.bind('<Double-1>', self.evEditMember) return nb
def showsets(self): if self.set_codes is None : self.set_codes = list_sets() tl = tix.Toplevel(self.main.master) lb = tix.ScrolledListBox(tl) lb.listbox.insert(0, *[x[0] for x in self.set_codes]) lb.listbox.configure(width=30, height=30, bg="#ffffff") tl.bind("<Escape>", tl.destroy) def finish(event): index = lb.listbox.curselection() if not len(index) : return self.search(self.set_codes[index[0]][1]) tl.destroy() lb.listbox.bind("<<ListboxSelect>>", finish) lb.pack(fill="both",expand=True)
def __init__(self, master=None, cards=list()): if master is None : self.main = tix.Tk() else : self.main = master self.main.resizable(False, True) # left part : list of all the cards self._cards = list() # for mention only ; self.update fills it # self._cards represents all the stored cards # self.cards is self._cards after user-filtering # see update and below self.names = tix.ScrolledListBox(self.main) self.names.listbox.configure(width=30, bg="#ffffff") # right part : single-card details and picture # top : picture self.imglbl = tix.Label(self.main) self.flipped = False # bottom : filters self.rightpart = tix.Frame(self.main) self.sort = LabelFrame(self.rightpart, text="Trier par : ") self.sortby = tix.StringVar(self.sort, "foreign_name") self.sort_buttons = list() for i, (d,s) in enumerate(SORT_PARAMS) : b = tix.Radiobutton(self.sort, text=d, value=s, variable=self.sortby) b.grid(row=i, column=0, sticky="w") self.sort_buttons.append(b) self.filter = LabelFrame(self.rightpart, text="Filtrer :") self.filter_query = tix.StringVar(self.filter) self.f_e = tix.Entry(self.filter, textvariable=self.filter_query, width=30) # buttons to add a card self.addacard = tix.Button(self.rightpart, text=" + ", command=self.search) self.askcode = tix.Button(self.rightpart, text=" ? ", command=self.showsets) self.set_codes = None self.main.bind_all("<Control-s>", self.save) self.main.bind_all("<Control-o>", self.load) self.names.listbox.bind_all("<<ListboxSelect>>", self.display_card) self.main.bind_all("<KP_Add>", self.inc) # "+" from the numeric pad self.main.bind_all("<plus>", self.inc) # "+" from the alphabetic pad self.main.bind_all("<KP_Subtract>", self.dec) # idem self.main.bind_all("<minus>", self.dec) self.sortby.trace("w", lambda x,y,z:self.update(self.cards)) self.filter_query.trace("w", lambda x,y,z:self.update()) self.imglbl.bind("<Button-1>",self.switch_img) self.names.pack(side="left", fill="y") self.imglbl.pack(side="top", fill="x") self.rightpart.pack(side="top", fill="both", expand=True) self.sort.grid(row=0, column=0, sticky="nsew") self.f_e.pack() self.filter.grid(row=0, column=1, columnspan=3, sticky="nsew") self.addacard.grid(row=1, column=3) self.askcode.grid(row=1, column=2) # these were useful when there was no filter above to fill the place... self.rightpart.grid_rowconfigure(0, weight=1) self.rightpart.grid_columnconfigure(1, weight=1) self.update(cards)