本文整理汇总了Python中tkinter.Listbox.grid方法的典型用法代码示例。如果您正苦于以下问题:Python Listbox.grid方法的具体用法?Python Listbox.grid怎么用?Python Listbox.grid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Listbox
的用法示例。
在下文中一共展示了Listbox.grid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Application
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid(sticky=N+S+E+W)
self.mainframe()
def mainframe(self):
self.data = Listbox(self, bg='red')
self.scrollbar = Scrollbar(self.data, orient=VERTICAL)
self.data.config(yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.data.yview)
for i in range(1000):
self.data.insert(END, str(i))
self.run = Button(self, text="run")
self.stop = Button(self, text="stop")
self.data.grid(row=0, column=0, rowspan=4,
columnspan=2, sticky=N+E+S+W)
self.data.columnconfigure(0, weight=1)
self.run.grid(row=4,column=0,sticky=EW)
self.stop.grid(row=4,column=1,sticky=EW)
self.scrollbar.grid(column=2, sticky=N+S)
示例2: FeasDisp
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
class FeasDisp(ttk.Frame):
"""Widget for displaying all of the feasible states in the conflict."""
def __init__(self, master=None, conflict=None, *args):
"""Initialize the widget."""
ttk.Frame.__init__(self, master, padding=5)
self.columnconfigure(1, weight=1)
self.rowconfigure(2, weight=1)
self.conflict = conflict
self.dispFormat = StringVar(value='pattern')
self.dispList = StringVar()
self.feasList = []
self.fmts = {'Pattern': 'YN-', 'List (YN)': 'YN',
'List (ordered and [decimal])': 'ord_dec'}
cBoxOpts = ('Pattern', 'List (YN)', 'List (ordered and [decimal])')
self.feasText = ttk.Label(self, text='Feasible States')
self.feasText.grid(row=0, column=0, columnspan=3)
self.cBox = ttk.Combobox(self, textvariable=self.dispFormat,
values=cBoxOpts, state='readonly')
self.cBoxLb = ttk.Label(self, text='Format:')
self.feasLBx = Listbox(self, listvariable=self.dispList)
self.scrl = ttk.Scrollbar(self, orient=VERTICAL,
command=self.feasLBx.yview)
# ###########
self.cBoxLb.grid(column=0, row=1, sticky=NSEW, pady=3)
self.cBox.grid(column=1, row=1, columnspan=2, sticky=NSEW, pady=3)
self.feasLBx.grid(column=0, row=2, columnspan=2, sticky=NSEW)
self.scrl.grid(column=2, row=2, sticky=NSEW)
self.cBox.bind('<<ComboboxSelected>>', self.fmtSel)
self.feasLBx.configure(yscrollcommand=self.scrl.set)
self.dispFormat.set('Pattern')
self.fmtSel()
def fmtSel(self, *args):
"""Action on selection of a new format."""
self.refreshList()
def setFeas(self, feasList):
"""Change the list of feasible states to be displayed."""
self.feasList = feasList
self.refreshList()
def refreshList(self):
"""Update the list of feasible states displayed and the format."""
fmt = self.fmts[self.dispFormat.get()]
if fmt == "YN-":
feas = self.conflict.feasibles.dash
if fmt == "YN":
feas = self.conflict.feasibles.yn
if fmt == "ord_dec":
feas = self.conflict.feasibles.ordDec
self.dispList.set(tuple(feas))
示例3: Listatag
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
def Listatag(self):
# Lista de tags * em fase de teste
title = ['189.186.63.44.20','123.145.584.55.5', '','','']
titleList = Listbox(self, height=5)
for t in title:
titleList.insert(END, t)
titleList.grid(row=7, column=2, columnspan=2, pady=5, sticky=W+E)
titleList.bind("<<ListboxSelect>>", self.newTitle)
示例4: __init__
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
class SpeciesListDialog:
def __init__(self, parent):
self.parent = parent
self.gui = Toplevel(parent.guiRoot)
self.gui.grab_set()
self.gui.focus()
self.gui.columnconfigure(0, weight=1)
self.gui.rowconfigure(1, weight=1)
Label(self.gui, text="Registered Species:").grid(row=0, column=0, pady=5, padx=5, sticky="w")
self.listRegisteredSpecies = Listbox(self.gui, width=70)
self.buttonAdd = Button(self.gui, text=" + ")
self.buttonDel = Button(self.gui, text=" - ")
self.listRegisteredSpecies.grid(row=1, column=0, columnspan=3, sticky="nswe", pady=5, padx=5)
self.buttonAdd.grid(row=2, column=1, pady=5, padx=5)
self.buttonDel.grid(row=2, column=2, pady=5, padx=5)
# Set (minimum + max) Window size
self.gui.update()
self.gui.minsize(self.gui.winfo_width(), self.gui.winfo_height())
# self.gui.maxsize(self.gui.winfo_width(), self.gui.winfo_height())
self.actionUpdate(None)
self.gui.bind("<<Update>>", self.actionUpdate)
self.gui.protocol("WM_DELETE_WINDOW", self.actionClose)
self.buttonDel.bind("<ButtonRelease>", self.actionDel)
self.buttonAdd.bind("<ButtonRelease>", self.actionAdd)
self.gui.mainloop()
def actionClose(self):
self.parent.guiRoot.event_generate("<<Update>>", when="tail")
self.gui.destroy()
def actionUpdate(self, event):
self.listRegisteredSpecies.delete(0, "end")
for (taxid, name) in self.parent.optimizer.speciesList:
self.listRegisteredSpecies.insert("end", taxid + ": " + name)
def actionDel(self, event):
try:
selection = self.listRegisteredSpecies.selection_get()
selectionSplit = selection.split(": ")
self.parent.optimizer.speciesList.remove((selectionSplit[0], selectionSplit[1]))
self.gui.event_generate("<<Update>>")
except tkinter.TclError:
# no selection
pass
def actionAdd(self, Event):
SpeciesSearchDialog(self.parent, self)
示例5: initUI
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
def initUI(self):
self.parent.title("TVstream manager")
self.stytle = ttk.Style()
self.pack(fill=BOTH, expand=1)
self.columnconfigure(0, weight=1, pad=2)
self.columnconfigure(2, weight=1, pad=2)
self.columnconfigure(4, pad=7)
#self.rowconfigure(3, weight=1)
#self.rowconfigure(4, weight=1, pad=7)
lbll = Label(self, text="Lingua")
lbll.grid(row=0,column=0,sticky=W, pady=4, padx=5)
lble = Label(self, text="Emittenti")
lble.grid(row=0,column=2,sticky=W, pady=1, padx=5)
global langlst
scrollang = Scrollbar(self)
langlst = Listbox(self,font='Arial 9',yscrollcommand=scrollang.set)
scrollang.config(command = langlst.yview)
for i in lingue:
langlst.insert(END, i)
langlst.focus_set()
langlst.bind("<<ListboxSelect>>", self.onSelectLang)
langlst.grid(row=1,column=0, columnspan=2, padx=6,sticky=E+W+S+N)
scrollang.grid(row=1,column=1, sticky=E+S+N)
global emitlst
scrollemit = Scrollbar(self)
emitlst = Listbox(self,font='Arial 9',yscrollcommand=scrollemit.set)
scrollemit.config(command = emitlst.yview )
emitlst.bind("<<ListboxSelect>>", self.onSelectEmittente)
emitlst.grid(row=1,column=2, columnspan=2, padx=5,sticky=E+W+S+N)
scrollemit.grid(row=1,column=3,sticky=E+S+N)
lbltxt = Label(self, text="Output log")
lbltxt.grid(row=2,column=0, columnspan=3, sticky=W, pady=4, padx=5)
global area
area = Text(self,height=10,font='Arial 9')
area.grid(row=3, column=0, columnspan=5, rowspan=1, padx=5, sticky=E+W+S+N)
scrolltxt = Scrollbar(self)
scrolltxt.config(command = area.yview)
scrolltxt.grid(row=3,column=4, columnspan=1, rowspan=1, sticky=E+N+S)
play = Button(self, text='Play', command=self.playUrl,
bg='gray', fg='black')
play.grid(row=1,column=4,padx=4,sticky=E+W)
示例6: _about_creatures
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
def _about_creatures(self):
lb = Listbox(self.frame,
height=15,
width=50,
selectmode=SINGLE)
lb.bind('<<ListboxSelect>>', self._onselect)
lb.grid(row=1, column=2)
items = self.model.creatures.items()
items = sorted(items, key=lambda k: k[0][0] * self.model.width + k[0][1])
for (x, y), creature in items:
lb.insert(END, [x, y, creature.life])
self.canvas = NeuroCanvas(self.frame, (2, 2), 400, 300)
示例7: ShapesMenu
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
class ShapesMenu(object):
"""
"""
def __init__(self, master, line_collection):
try:
self.width_of_entry = len(line_collection[0])
except IndexError:
self.width_of_entry = 0
self.top = Toplevel(master)
self.current_lines_listbox = Listbox(self.top)
self.removed_lines_listbox = Listbox(self.top)
self.submit = Button(self.top, text = "Ok", command=self.submit)
self.remove_button = Button(self.top, text = "Remove", command=self.remove_line)
self.cancel = Button(self.top, text = "Cancel", command=self.top.destroy)
self.top.bind("<Return>", func=self.submit)
self.current_lines = line_collection
self.removed_lines = []
self.ids_internal = []
self.ids = []
for index, line in enumerate(self.current_lines):
#removes the point data and converts the rest to strings
id = line[1]
if id not in self.ids_internal:
self.ids_internal.append(id)
self.ids.append(id)
line = [str(element) for element in line[1:]]
#put into the list
self.current_lines_listbox.insert(index, " ".join(line))
self.current_lines_listbox.grid(row=0, column=0, columnspan=3)
self.submit.grid(row=1, column=1)
self.cancel.grid(row=1, column=2)
self.remove_button.grid(row=1, column=0)
def submit(self):
#expose the internal IDs to remove to the exterior methods
self.ids = self.ids_internal
self.top.destroy()
def remove_line(self):
"""Take the active line and remove it"""
line_to_remove = self.current_lines_listbox.get(ANCHOR)
id_to_remove = int(line_to_remove.split(" ")[0])
#remove it from the ID list
self.ids_internal.remove(id_to_remove)
#remove it from the listbox
self.current_lines_listbox = self.current_lines_listbox.delete(ANCHOR)
示例8: CreateSets
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
class CreateSets(Frame):
def __init__(self, parent):
# super(createSets,self).__init__(parent)
Frame.__init__(self, parent)
self.parent = parent
self.grid(row=0, column=0)
self.parentWindow = 0
self.listBox = Listbox(self, selectmode=EXTENDED)
self.listBox.grid(row=1, column=1)
for item in ["one", "two", "three", "four"]:
self.listBox.insert(END, item)
self.buttonDel = Button(self,
text="delite selected class",
command=self.del_selected) # lambda ld=self.listBox:ld.delete(ANCHOR))
self.buttonDel.grid(row=0, column=0)
self.entry = Entry(self, state=NORMAL)
# self.entry.focus_set()
self.entry.insert(0, "default")
self.entry.grid(row=1, column=0)
self.buttonInsert = Button(self, text="add new class",
command=self.add)
self.buttonInsert.grid(row=0, column=1)
self.buttonDone = Button(self, text="done", command=self.done)
self.buttonDone.grid(row=2, column=0)
def done(self):
self.parentWindow.childResultList = self.listBox.get(0, END)
# print(self.listBox.get(0, END))
self.parent.destroy()
def add(self):
text = self.entry.get()
self.listBox.insert(END, text)
def del_selected(self):
lb = self.listBox
items = map(int, lb.curselection())
for item in items:
lb.delete(item)
示例9: initUI
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
def initUI(self):
self.parent.title("Listbox")
self.pack(fill=BOTH, expand=1)
IP_list = ['IP Address 1', 'IP Address 2', 'IP Address 3', 'IP Address 4', 'IP Address 5', 'IP Address 6', 'IP Address 7', 'IP Address 8', 'IP Address 9', 'IP Address 10', 'IP Address 11', 'IP Address 12', 'IP Address 13', 'IP Address 14', 'IP Address 15', 'IP Address 16']
IP_numbers = ['150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1', '150.0.0.1']
lb = Listbox(self)
for i in IP_list:
lb.insert(END, i)
lb.bind("<<ListboxSelect>>", self.onSelect)
lb.place(x=20, y=20)
self.var = StringVar()
self.label = Label(self, text=0, textvariable=self.var)
self.label.place(x=20, y=270)
#
self.columnconfigure(1, weight=1)
self.columnconfigure(3, pad=7)
self.rowconfigure(3, weight=1)
self.rowconfigure(5, pad=7)
#lbl = Label(self, text="Windows")
lb.grid(sticky=W, pady=40, padx=50)
#lb = Text(self)
lb.grid(row=1, column=0, columnspan=2, rowspan=4,
padx=50, sticky=E+W+S+N)
abtn = Button(self, text="Activate")
abtn.grid(row=1, column=3)
cbtn = Button(self, text="Close")
cbtn.grid(row=2, column=3, pady=4)
hbtn = Button(self, text="Help")
hbtn.grid(row=5, column=0, padx=5)
obtn = Button(self, text="OK")
obtn.grid(row=5, column=3)
示例10: new_random_swiss
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
def new_random_swiss(main):
players = []
def add_player(event):
if e.get() is "":
return
players.append(e.get())
Lb.delete(0,END)
for x in players:
Lb.insert(0,x)
e.delete(0,END)
def remove_player():
l=len(players)-1
if Lb.curselection():
for x in Lb.curselection():
Lb.delete(x)
players.pop(l-x)
else:
Lb.delete(0)
players.pop(-1)
Lb.delete(0,END)
for x in players:
Lb.insert(0,x)
top = Toplevel(main)
top.title("New Random Swiss")
top.bind("<Return>",add_player)
center_size(top,360,180)
Label(top, text='Name:').grid(row=0,column=0)
e = Entry(top,width=12)
e.grid(row=0,column=1)
e.focus_force()
Button(top,text='Add', command=lambda:add_player(None) ).grid(row=1,column=0)
Button(top,text='Remove', command=remove_player ).grid(row=1,column=1)
Button(top,text='Cancel', command=top.destroy ).grid(row=2,column=0)
Button(top,text='Finish', command=lambda:create_single_swiss(players,main)).grid(row=2,column=1)
Sb = Scrollbar(top)
Sb.grid(row=0,column=3,rowspan=3)
Lb = Listbox(top,selectmode=EXTENDED,yscrollcommand=Sb.set)
Lb.grid(row=0,rowspan=3,column=2)
Sb.config(command=Lb.yview)
示例11: setupGui
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
def setupGui():
global window
global labelShows, labelEpisodes, labelDownloads
global listShows, listEps, listDownloads
global btnAbout, btnDownload, btnChooseFolder
global folderFrame
global folderName
window = Tk()
window.title('iView')
window.minsize(300, 200)
labelShows = Label(window, text='Shows')
labelShows.grid(column=0, row=0, sticky=[N,S,E,W])
listShows = Listbox(window)
listShows.grid(column=0, row=1, sticky=[N,S,E,W])
listShows.bind('<<ListboxSelect>>', indexEpsEv)
indexShows()
labelEpisodes = Label(window, text='Episodes')
labelEpisodes.grid(column=1, row=0, sticky=[N,S,E,W])
listEps = Listbox(window)
listEps.grid(column=1, row=1, sticky=[N,S,E,W])
listEps.bind('<<ListboxSelect>>', setEpNumEv)
indexEps(0)
labelDownloads = Label(window, text='Downloads')
labelDownloads.grid(column=2, row=0, sticky=[N,S,E,W])
listDownloads = Listbox(window)
listDownloads.grid(column=2, row=1, sticky=[N,S,E,W])
btnAbout = Button(window, text='About', command=about)
btnAbout.grid(column=0, row=2, sticky=[N,S,E,W])
btnDownload = Button(window, text='Download', command=download)
btnDownload.grid(column=1, row=2, sticky=[N,S,E,W])
btnChooseFolder = Button(window, text='Choose Download Folder', command=chooseDir)
btnChooseFolder.grid(column=2, row=2, sticky=[N,S,E,W])
folderName = Text(window, height=1)
folderName.grid(column=0, row=3, columnspan=3)
folderName.insert(END, expanduser("~")+(':Videos:iView:'.replace(':', os.sep)))
window.columnconfigure(0, weight=1)
window.columnconfigure(1, weight=1)
window.columnconfigure(2, weight=1)
window.rowconfigure(1, weight=1)
def updateDownloadList():
refreshDownloadList()
window.after(1000, updateDownloadList)
dlListThrd = threading.Thread(target=updateDownloadList)
dlListThrd.setName('Update Download List')
dlListThrd.start()
示例12: SelectDeviceFrame
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
class SelectDeviceFrame(CopilotInnerFrame):
def __init__(self, master, config, state):
super(SelectDeviceFrame, self).__init__(master, config)
self._state = state
if self._state.action == 'copy':
self._frame_lbl['text'] = 'Copy To Device'
elif self._state.action == 'delete':
self._frame_lbl['text'] = 'Delete From Device'
self._next_btn['command'] = self._next_cmd
self._dev_list = Listbox(self._master, font=self._config.item_font)
self._dev_list.grid(row=1, column=0, columnspan=3, sticky='nsew')
self._dev_list.configure(yscrollcommand=self._sb.set)
self._sb['command'] = self._dev_list.yview
self._refresh_drives()
def _next_cmd(self):
if len(self._dev_list.curselection()) > 0:
item_idx = int(self._dev_list.curselection()[0])
self._state.to_device = self._parts[item_idx]
if self._state.action == 'copy':
self._new_state_window(DeviceToFrame, self._state)
elif self._state.action == 'delete':
self._new_state_window(CopyFileFrame, self._state)
def _refresh_drives(self):
self._parts = []
for drive in usb_drives():
for part in drive.partitions():
drive_opt = DriveOption(drive, part)
self._parts.append(drive_opt)
self._dev_list.insert('end', drive_opt)
示例13: Application
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
class Application():
def __init__(self, master, network, debug=False):
"""
Init method for the Application class, this method is the GUI
Class for our solution, it gets master (Tk root, network
and debug (Open debug window if needded)
:param master: The root Tk of the Application
:param network: network is object from Network class (communication)
:param debug: bool, to open or not..
"""
self.init_constants(master, network) # create constants
self.__create_top_toolbar()
self.__create_app_frame()
self.bindings()
self.__network.listen() # network mainloop..
if debug:
self.debug = True
self.open_debug_dialog()
def init_constants(self, master, network):
"""
This function contruct all the vital constant
for this class it gets the root and the network
and save them as constant of the class
:param master: The root Tk of the Application
:param network: network is object from Network class (communication)
"""
self.__master_splinter = master
self.__user_color = StringVar()
self.__current_shape = None
self.__drawing_shape = None
self.__users_list = []
self.__points = [] # private because I dont want that someone change them
self.__network = network # private for the same reason
self.debug = False
def __create_app_frame(self):
"""
This function creates and pack (using grid) the main app frame
(The left toolbar (users list) and the canvas
"""
app_frame = Frame(self.__master_splinter)
self.create_game_canvas(app_frame)
self.create_left_toolbar(app_frame)
app_frame.grid(row=1)
def create_game_canvas(self, app_frame):
"""
This function creates and pack the game canvas
:param app_frame: Tk frame object
"""
self.canvas = Canvas(app_frame, width=500, height=500, bg='white')
self.canvas.grid(column=1)
def __create_top_toolbar(self):
"""
This function creates and pack the top toolbar (with all the colors, shapes
and etc..
"""
top_toolbar = Frame(self.__master_splinter)
help_button = Button(top_toolbar, text="Help", command=self.open_help_dialog)
help_button.grid(row=0, column=4)
color_frame = self.create_color_frame(top_toolbar)
color_frame.grid(row=0, column=0)
empty_label = Label(top_toolbar, padx=20)
empty_label.grid(column=1, row=0)
my_shapes_frame = self.create_shape_buttons(top_toolbar)
my_shapes_frame.grid(row=0, column=2)
empty_label = Label(top_toolbar, padx=45)
empty_label.grid(column=3, row=0)
top_toolbar.grid(row=0)
def create_left_toolbar(self, app_frame):
"""
This function creates and pack the left toolbar
:param app_frame: root for this toolbar.. (Frame obj)
:return:
"""
left_toolbar = Frame(app_frame)
self.lb_users = Listbox(left_toolbar)
self.lb_users.config(height=30)
self.lb_users.grid(row=0, column=0)
scroll_bar = Scrollbar(left_toolbar)
scroll_bar.config(command=self.lb_users.yview)
scroll_bar.grid(row=0, column=1, sticky='ns')
left_toolbar.propagate("false")
left_toolbar.grid(column=0, row=0)
self.lb_users.config(yscrollcommand=scroll_bar.set)
self.debug_event("Left toolbar was generated")
def create_shape_buttons(self, root):
"""
This function get a root and creates all the shapes
buttons (because they have picture they need to
compile and resize the icons...
#.........这里部分代码省略.........
示例14: Add_Recipe_Modal
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
class Add_Recipe_Modal(Modal):
def __init__(self, parent=None, title="Add Recipe"):
self.shorts = []
self.amounts = None
self.ingredients = None
Modal.__init__(self, parent, title, geometry="375x410" if system() == "Windows" else "375x350")
def initialize(self):
amount_label = Label(self, width=8, text="Amount")
amount_label.grid(row=0, column=0)
ingredients_label = Label(self, width=35, text="Item Name")
ingredients_label.grid(row=0, column=1)
self.amounts_list = Listbox(self, width=8, selectmode="single")
self.amounts_list.bind("<Double-Button-1>", self.edit)
self.amounts_list.grid(row=1, column=0, sticky="E")
self.ingredients_list = Listbox(self, width=35, selectmode="single")
self.ingredients_list.bind("<Double-Button-1>", self.edit)
self.ingredients_list.grid(row=1, column=1)
add_button = Button(self, width=7, text="Add", command=self.add)
self.bind("<Control-+>", self.add)
self.bind("<Insert>", self.add)
add_button.grid(row=2, column=1, sticky="E")
remove_button = Button(self, text="Remove", command=self.remove)
self.bind("<Delete>", self.remove)
remove_button.grid(row=2, column=0)
produces_label = Label(self, text="Produces: ")
produces_label.grid(row=3, column=0, sticky="W")
self.produces_box = Entry(self, width=5)
self.produces_box.insert(0, "1")
self.produces_box.grid(row=3, column=1, sticky="W")
machine_label = Label(self, text="Machine: ")
machine_label.grid(row=4, column=0, sticky="W")
self.machine_box = Entry(self)
self.machine_box.grid(row=4, column=1, sticky="EW")
info_label = Label(self, text="Extra Info: ")
info_label.grid(row=5, column=0, sticky="W")
self.info_box = Entry(self)
self.info_box.grid(row=5, column=1, sticky="EW")
cancel_button = Button(self, text="Cancel", width=7, command=self.cancel)
self.bind("<Escape>", self.cancel)
cancel_button.grid(row=6, column=0, pady=10)
ok_button = Button(self, text="OK", width=7, command=self.ok)
self.bind("<Return>", self.ok)
ok_button.grid(row=6, column=1, pady=10, sticky="E")
self.bind("<<ListboxSelect>>", self.sync)
def sync(self, event):
if event.widget is self.amounts_list and len(self.amounts_list.curselection()) != 0:
self.ingredients_list.selection_set(self.amounts_list.curselection()[0])
def add(self, event=None):
short, name, amount = Add_Ingredient_Modal().show()
if short is not None and name is not None and amount is not None:
if name not in self.ingredients_list.get(0, "end"):
self.ingredients_list.insert("end", name)
self.amounts_list.insert("end", amount)
self.shorts.append(short)
def edit(self, event=None):
if len(self.ingredients_list.curselection()) != 0:
index = self.ingredients_list.curselection()[0]
current_short = self.shorts[index]
current_name = self.ingredients_list.get(index)
current_amount = self.amounts_list.get(index)
new_short, new_name, new_amount = Edit_Ingredient_Modal().show(current_short, current_name, current_amount)
if new_short is not None and new_name is not None and new_amount is not None:
self.amounts_list.delete(index)
self.ingredients_list.delete(index)
self.amounts_list.insert(index, new_amount)
self.ingredients_list.insert(index, new_name)
self.shorts[index] = new_short
def remove(self, event=None):
if len(self.ingredients_list.curselection()) != 0:
slct = int(self.ingredients_list.curselection()[0])
self.ingredients_list.delete(slct)
self.amounts_list.delete(slct)
del(self.shorts[slct])
def ok(self, event=None):
if len(self.ingredients_list.get(0)) != 0 and self.produces_box is not None and self.produces_box.get().isdigit():
self.produces = int(self.produces_box.get())
self.amounts = self.amounts_list.get(0, last="end")
self.ingredients = self.ingredients_list.get(0, last="end")
self.machine = self.machine_box.get()
#.........这里部分代码省略.........
示例15: ListboxVidget
# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import grid [as 别名]
#.........这里部分代码省略.........
self._scrollbar_yview.config(command=self._listbox.yview)
# Bind single-click event handler
self._listbox.bind('<Button-1>', self._on_single_click)
# Bind double-click event handler
self._listbox.bind('<Double-Button-1>', self._on_double_click)
# Update listbox widget
self._listbox_widget_update(keep_active=False)
# Update widget
self._widget_update()
def _widget_update(self):
"""
Update widget.
@return: None.
"""
# Row 0 for listbox and y-axis scrollbar
self.widget().rowconfigure(0, weight=1)
# Row 1 for x-axis scrollbar
self.widget().rowconfigure(1, weight=0)
# Column 0 for listbox and x-axis scrollbar
self.widget().columnconfigure(0, weight=1)
# Column 1 for y-axis scrollbar
self.widget().columnconfigure(1, weight=0)
# Lay out listbox
self._listbox.grid(row=0, column=0, sticky='NSEW')
# Lay out x-axis scrollbar
self._scrollbar_xview.grid(row=1, column=0, sticky='EW')
# Lay out y-axis scrollbar
self._scrollbar_yview.grid(row=0, column=1, sticky='NS')
def is_enabled(self):
"""
Test whether the listbox is enabled.
@return: Boolean.
"""
# Return whether the listbox is enabled
return self._listbox.config('state')[4] != DISABLED
def is_changing(self):
"""
Test whether the listbox is changing.
@return: Boolean.
"""
# Return whether the listbox is changing
return self._is_changing
def is_resetting(self):
"""
Test whether the listbox is setting active index to the same value.
@return: Boolean.
"""
# Return whether the listbox is setting active index to the same value