当前位置: 首页>>代码示例>>Python>>正文


Python Listbox.bind方法代码示例

本文整理汇总了Python中tkinter.Listbox.bind方法的典型用法代码示例。如果您正苦于以下问题:Python Listbox.bind方法的具体用法?Python Listbox.bind怎么用?Python Listbox.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkinter.Listbox的用法示例。


在下文中一共展示了Listbox.bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [as 别名]
  def __init__(self, *, multiple_runner_class, input_spec, left_name,
               right_name):
    """Sets up windows and the instance of RunMultipleTimes that will do the actual work."""
    #: The input_spec is an iterable of
    #: :py:class:`farg.core.read_input_spec.SpecificationForOneRun`.
    self.input_spec = input_spec
    #: Class responsible for the actual running multiple times.
    self.multiple_runner_class = multiple_runner_class
    #: Main window
    self.mw = mw = Tk()
    #: Statistics thus far, grouped by input.
    self.stats = AllStats(left_name=left_name, right_name=right_name)

    #: Are we in the process of quitting?
    self.quitting = False

    self.status_label = Label(
        mw, text='Not Started', font=('Times', 20), foreground='#000000')
    self.status_label_text = self.status_label.cget('text')
    self.status_label.pack(side=TOP, expand=True, fill=X)

    #: Has a run started? Used to ensure single run.
    self.run_started = False

    details_frame = Frame(mw)
    details_frame.pack(side=TOP)
    #: listbox on left listing inputs.
    frame = Frame(details_frame)
    scrollbar = Scrollbar(frame, orient=VERTICAL)
    listbox = Listbox(
        frame,
        yscrollcommand=scrollbar.set,
        height=25,
        width=70,
        selectmode=SINGLE)
    scrollbar.config(command=listbox.yview)
    scrollbar.pack(side=RIGHT, fill=Y)
    listbox.pack(side=LEFT, fill=BOTH, expand=1)
    listbox.bind('<ButtonRelease-1>', self.SelectForDisplay, '+')
    frame.pack(side=LEFT)
    self.listbox = listbox
    #: Canvas on right for details
    self.canvas = Canvas(
        details_frame,
        width=kCanvasWidth,
        height=kCanvasHeight,
        background='#FFFFFF')
    self.canvas.pack(side=LEFT)
    #: which input are we displaying the details of?
    self.display_details_for = None

    #: Thread used for running
    self.thread = None
    self.mw.bind('<KeyPress-q>', lambda e: self.Quit())
    self.mw.bind('<KeyPress-r>', lambda e: self.KickOffRun())
    self.Refresher()
    self.mw.after(1000, self.KickOffRun)
开发者ID:amahabal,项目名称:PySeqsee,代码行数:59,代码来源:non_interactive.py

示例2: setupGui

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [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()
开发者ID:gitter-badger,项目名称:python-iview,代码行数:59,代码来源:iview-tk.py

示例3: Listatag

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [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)
开发者ID:phods,项目名称:tagout,代码行数:11,代码来源:testejanela.py

示例4: initUI

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [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)
开发者ID:vinloren,项目名称:tvstreams,代码行数:52,代码来源:TVstreamtk.py

示例5: LabeledListBox

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [as 别名]
class LabeledListBox(Frame):
    def __init__(self, parent, list_model, label_text):
        Frame.__init__(self, parent)

        self._list_model = list_model
        self._list_objects = []
        self._selected_items = []
        scrollbar = Scrollbar(self, orient=VERTICAL)
        Label(self, text=label_text).pack()
        self.listbox = Listbox(self, selectmode=EXTENDED, exportselection=0, yscrollcommand=scrollbar.set, borderwidth=0, highlightthickness=0)
        scrollbar.config(command=self.listbox.yview)
        scrollbar.pack(side=RIGHT, fill=Y)
        self.listbox.pack(side=LEFT, fill=BOTH, expand=1)
        self.listbox.bind('<<ListboxSelect>>', self._on_select)
        self._list_model.list_items_model.add_listener(self._list_items_changed)
        self._list_model.selected_items_model.add_listener(self._selected_items_changed)
        self._update_list_items()

    def _list_items_changed(self, values):
        self._update_list_items()

    def _selected_items_changed(self, values):
        self._update_selected_items()

    def _update_list_items(self):
        values, labels = self._list_model.list_items_model.get_list_values()
        if not values == self._list_objects:
            self._list_objects = []
            self._selected_items = []
            self.listbox.delete(0, END)
            for value, label in zip(values, labels):
                self._list_objects.append(value)
                self.listbox.insert(END, label)
            self._update_selected_items()

    def _update_selected_items(self):
        selected_items = self._list_model.selected_items_model.selected_items
        if not selected_items == self._selected_items:
            self._selected_items = selected_items
            for index, list_item in enumerate(self._list_objects):
                if list_item in selected_items:
                    self.listbox.selection_set(index)

    def _on_select(self, evt):
        visible_selected_indices = self.listbox.curselection()
        for index, list_item in enumerate(self._list_objects):
            if index in visible_selected_indices:
                self._list_model.selected_items_model.select(list_item)
            else:
                self._list_model.selected_items_model.deselect(list_item)
开发者ID:tomdoel,项目名称:pyxnatbrowser,代码行数:52,代码来源:labeledlistbox.py

示例6: _about_creatures

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [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)
开发者ID:ktulhy-kun,项目名称:neurolife,代码行数:17,代码来源:info_window.py

示例7: initUI

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [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)
开发者ID:dfitz360,项目名称:Drop-py,代码行数:47,代码来源:RossLearning.py

示例8: initUI

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [as 别名]
    def initUI(self):
        self.parent.title("Listbox")
        self.pack(fill=BOTH, expand=1)

        acts = ["Scarlett Johansson", "Rachel Weiss", "Natalie Portman", "Jessica Alba", "Angelina jolie", "Emma Stone", "Sandra Bullock", "Julia Roberts",
        "Jennifer Lawrence", "Mila Kunis", "Jennifer Aniston", "Charlize Theron", "Cameron Diaz", "Nicole Kidman", "Meryl Streep", "Reese Witherspoon"]

        lb = Listbox(self, selectmode="multiple")
        for i in acts:
            lb.insert(END, i)

        lb.bind("<<ListboxSelect>>", self.onSelect)

        lb.pack(pady=15)

        self.var = StringVar()
        self.label = Label(self, text=0, textvariable=self.var)
        self.label.pack()
开发者ID:Exodus111,项目名称:Projects,代码行数:20,代码来源:listbox.py

示例9: initUI

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [as 别名]
    def initUI(self):
        self.parent.title("Listbox")
        self.pack(fill=BOTH, expand=1)

        acts = ['Scarlett Johansson', 'Rachel Weiss',
            'Natalie Portman', 'Jessica Alba']

        lb = Listbox(self)
        for i in acts:
            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=210)
开发者ID:KimBoWoon,项目名称:Python_Practice,代码行数:20,代码来源:TKBook.py

示例10: __init__

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [as 别名]
class MiniWindow:
    def __init__(self,root,list):
        self.list = list
        self.mini = Toplevel(root)
        self.mini.wm_title("Matches")
        print (root.winfo_screenwidth())
        self.mini.geometry("%dx%d+%d+%d" %(500,200,root.winfo_x()+root.winfo_width(),root.winfo_y()))
        self.filelist = Listbox(self.mini)
        for item in self.list:
            self.filelist.insert('end',str(item))
        self.filelist.bind("<<ListboxSelect>>",self.onClick)
        self.filelist.pack(fill="both")
    def onClick(self,event):
        print(self.filelist.curselection())
        index = int(self.filelist.curselection()[0])
        link = self.list[index]
        filedir = os.path.dirname(link)
        if os.name == 'nt':
            os.startfile(filedir)
        elif os.name == 'posix':
            subprocess.Popen(["xdg-open",filedir])
开发者ID:bretttjohnson1,项目名称:Duplicate_Discoverer,代码行数:23,代码来源:window.py

示例11: ShiftReduceApp

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [as 别名]
class ShiftReduceApp(object):
    """
    A graphical tool for exploring the shift-reduce parser.  The tool
    displays the parser's stack and the remaining text, and allows the
    user to control the parser's operation.  In particular, the user
    can shift tokens onto the stack, and can perform reductions on the
    top elements of the stack.  A "step" button simply steps through
    the parsing process, performing the operations that
    ``nltk.parse.ShiftReduceParser`` would use.
    """
    def __init__(self, grammar, sent, trace=0):
        self._sent = sent
        self._parser = SteppingShiftReduceParser(grammar, trace)

        # Set up the main window.
        self._top = Tk()
        self._top.title('Shift Reduce Parser Application')

        # Animations.  animating_lock is a lock to prevent the demo
        # from performing new operations while it's animating.
        self._animating_lock = 0
        self._animate = IntVar(self._top)
        self._animate.set(10) # = medium

        # The user can hide the grammar.
        self._show_grammar = IntVar(self._top)
        self._show_grammar.set(1)

        # Initialize fonts.
        self._init_fonts(self._top)

        # Set up key bindings.
        self._init_bindings()

        # Create the basic frames.
        self._init_menubar(self._top)
        self._init_buttons(self._top)
        self._init_feedback(self._top)
        self._init_grammar(self._top)
        self._init_canvas(self._top)

        # A popup menu for reducing.
        self._reduce_menu = Menu(self._canvas, tearoff=0)

        # Reset the demo, and set the feedback frame to empty.
        self.reset()
        self._lastoper1['text'] = ''

    #########################################
    ##  Initialization Helpers
    #########################################

    def _init_fonts(self, root):
        # See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
        self._sysfont = tkinter.font.Font(font=Button()["font"])
        root.option_add("*Font", self._sysfont)

        # TWhat's our font size (default=same as sysfont)
        self._size = IntVar(root)
        self._size.set(self._sysfont.cget('size'))

        self._boldfont = tkinter.font.Font(family='helvetica', weight='bold',
                                    size=self._size.get())
        self._font = tkinter.font.Font(family='helvetica',
                                    size=self._size.get())

    def _init_grammar(self, parent):
        # Grammar view.
        self._prodframe = listframe = Frame(parent)
        self._prodframe.pack(fill='both', side='left', padx=2)
        self._prodlist_label = Label(self._prodframe,
                                     font=self._boldfont,
                                     text='Available Reductions')
        self._prodlist_label.pack()
        self._prodlist = Listbox(self._prodframe, selectmode='single',
                                 relief='groove', background='white',
                                 foreground='#909090',
                                 font=self._font,
                                 selectforeground='#004040',
                                 selectbackground='#c0f0c0')

        self._prodlist.pack(side='right', fill='both', expand=1)

        self._productions = list(self._parser.grammar().productions())
        for production in self._productions:
            self._prodlist.insert('end', (' %s' % production))
        self._prodlist.config(height=min(len(self._productions), 25))

        # Add a scrollbar if there are more than 25 productions.
        if 1:#len(self._productions) > 25:
            listscroll = Scrollbar(self._prodframe,
                                   orient='vertical')
            self._prodlist.config(yscrollcommand = listscroll.set)
            listscroll.config(command=self._prodlist.yview)
            listscroll.pack(side='left', fill='y')

        # If they select a production, apply it.
        self._prodlist.bind('<<ListboxSelect>>', self._prodlist_select)

        # When they hover over a production, highlight it.
#.........这里部分代码省略.........
开发者ID:52nlp,项目名称:Text-Summarization,代码行数:103,代码来源:srparser_app.py

示例12: __init__

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [as 别名]
class Controller:
    SNAP_RADIUS = 5

    def __init__(self, tk: Tk):
        tk.title("Layered Polygons")

        menubar = Menu(tk)

        menu_file = Menu(menubar, tearoff=0)
        menu_file.add_command(label="New...", command=self._new_scene)
        menu_file.add_command(label="Open...", command=self._open_scene)
        menu_file.add_separator()
        menu_file.add_command(label="Save", command=self._save_scene)
        menu_file.add_command(label="Save As...", command=self._save_scene_as)
        menu_file.add_separator()
        menu_export = Menu(menu_file, tearoff=0)
        menu_export.add_command(label="Wavefront (.obj)...",
                                command=self._export_obj)
        menu_file.add_cascade(label="Export As", menu=menu_export)
        menu_file.add_separator()
        menu_file.add_command(label="Quit", command=self._quit_app)
        menubar.add_cascade(label="File", menu=menu_file)

        tk.config(menu=menubar)

        paned = PanedWindow(tk, relief=RAISED)
        paned.pack(fill=BOTH, expand=1)

        frame = Frame(paned)
        paned.add(frame)
        self._canvas = LayPolyCanvas(frame)
        bar_x = Scrollbar(frame, orient=HORIZONTAL)
        bar_x.pack(side=BOTTOM, fill=X)
        bar_x.config(command=self._canvas.xview)
        bar_y = Scrollbar(frame, orient=VERTICAL)
        bar_y.pack(side=RIGHT, fill=Y)
        bar_y.config(command=self._canvas.yview)
        self._canvas.config(xscrollcommand=bar_x.set, yscrollcommand=bar_y.set)
        self._canvas.pack(side=LEFT, expand=True, fill=BOTH)
        # Thanks to the two guys on Stack Overflow for that!
        # ( http://stackoverflow.com/a/7734187 )

        self._layer_list = Listbox(paned, selectmode=SINGLE)
        paned.add(self._layer_list)

        self._scene = None
        self._current_layer = None
        self._is_drawing_polygon = False
        self._tk = tk

        self._canvas.bind("<Button-1>", self._canvas_left_click)
        self._canvas.bind("<Button-3>", self._canvas_right_click)
        self._canvas.bind("<Motion>", self._canvas_mouse_moved)
        self._layer_list.bind("<<ListboxSelect>>", self._layer_change)

        self._current_path = None

    def _canvas_left_click(self, event):
        if not self._scene or not self._current_layer:
            return
        x, y = self._canvas.window_to_canvas_coords(event.x, event.y)

        if self._is_drawing_polygon:
            polygon = self._current_layer.get_polygon_at(-1)

            # Move vtx away from mouse to not interfere with search for closest
            polygon.get_vertex_at(-1).\
                set_coords(x-self.SNAP_RADIUS, y-self.SNAP_RADIUS)

            closest_vertex = self._current_layer.get_closest_vertex(
                x, y, self.SNAP_RADIUS)

            if closest_vertex:
                polygon.remove_vertex_at(-1)
                if closest_vertex is polygon.get_vertex_at(0):
                    self._is_drawing_polygon = False
                else:
                    polygon.add_vertex(closest_vertex)
                    polygon.add_vertex(Vertex(x, y))
            else:
                polygon.get_vertex_at(-1)\
                    .set_coords(x, y)
                polygon.add_vertex(Vertex(x, y))

            self._canvas.notify_polygon_change(self._current_layer
                                               .get_polygon_count()-1)
        else:
            # Create start vertex or use already existing one
            start_vertex = self._current_layer\
                .get_closest_vertex(x, y, self.SNAP_RADIUS)
            if not start_vertex:
                start_vertex = Vertex(x, y)

            # Vertex for mouse cursor
            next_vertex = Vertex(x, y)

            self._current_layer.add_polygon(
                Polygon([start_vertex, next_vertex]))

            self._is_drawing_polygon = True
#.........这里部分代码省略.........
开发者ID:tobchen,项目名称:LayeredPolygons,代码行数:103,代码来源:controller.py

示例13: Add_Recipe_Modal

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [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()
#.........这里部分代码省略.........
开发者ID:nalexander50,项目名称:MCRC-JSON-Creator,代码行数:103,代码来源:Add_Recipe_Modal.py

示例14: ListboxVidget

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [as 别名]

#.........这里部分代码省略.........
            relief='groove',
            activestyle='none',
            highlightthickness=0,
            # Active index cache only supports single-selection mode for now.
            # See 2N6OR.
            selectmode='single',
        )

        # Set the listbox widget as config target
        self.config_target_set(self._listbox)

        # Create x-axis scrollbar
        self._scrollbar_xview = _HiddenScrollbar(
            self.widget(),
            orient=HORIZONTAL,
        )

        # Create y-axis scrollbar
        self._scrollbar_yview = _HiddenScrollbar(
            self.widget(),
            orient=VERTICAL,
        )

        # Mount scrollbars
        self._listbox.config(xscrollcommand=self._scrollbar_xview.set)

        self._listbox.config(yscrollcommand=self._scrollbar_yview.set)

        self._scrollbar_xview.config(command=self._listbox.xview)

        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
开发者ID:AoiKuiyuyou,项目名称:AoikRegistryEditor,代码行数:70,代码来源:listbox.py

示例15: GUI

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import bind [as 别名]
class GUI(Frame):  # pylint: disable=too-many-ancestors
    """class for GUI"""
    static_logger = logging.getLogger(__name__)
    static_queue = queue.Queue()

    def __init__(self, parent, db, pab, alg):
        """init"""
        Frame.__init__(self, parent)
        self.right_list = Listbox(parent)
        self.left_list = Listbox(parent)
        self.parent = parent
        self.db_creator = db
        self.path_and_bag = pab
        self.alg_do = alg
        self.menu_bar = Menu(self.parent)
        self.init_ui()

    def init_ui(self):
        """getting all things started"""
        self.parent.title("PyMeno")
        self.left_list.bind("<Double-Button-1>", self.on_double_click)
        self.parent.config(menu=self.menu_bar)
        file_menu = Menu(self.menu_bar, tearoff=False)
        menu2_parse = Menu(self.menu_bar, tearoff=False)
        # menu3_parse = Menu(menu_bar, tearoff=False)
        # sub_menu = Menu(file_menu, tearoff=False)
        self.left_list.pack(side=LEFT, fill=BOTH, expand=2)
        self.right_list.pack(side=RIGHT, fill=BOTH, expand=2)

        # add something to menu

        file_menu.add_command(label="Choose folder with music ALG 1",
                              underline=0, command=self.new_thread_2)
        file_menu.add_command(label="Choose folder with music ALG 2",
                              underline=0, command=self.new_thread_1)
        file_menu.add_command(label="Choose folder with music ALG 3",
                              underline=0, command=self.new_thread_2)
        file_menu.add_command(label="Exit", underline=0, command=self.on_exit)

        menu2_parse.add_command(label="Download artists list", underline=0,
                                command=self.db_creator.download_list_of_artists)
        menu2_parse.\
            add_command(label="Parse artists information to database", underline=0,
                        command=self.go_to_lilis_parsing)

        self.menu_bar.add_cascade(label="File", underline=0, menu=file_menu)
        self.menu_bar.add_cascade(label="Data", underline=0, menu=menu2_parse)

    def on_exit(self):
        """quit"""
        GUI.static_queue.put("endino-tarantino")
        self.quit()

    def disable_menu(self):
        """disable menu while program is working"""
        self.menu_bar.entryconfig("File", state="disabled")
        self.menu_bar.entryconfig("Data", state="disabled")

    def enable_menu(self):
        """enable menu after work"""
        self.menu_bar.entryconfig("File", state="normal")
        self.menu_bar.entryconfig("Data", state="normal")

    def new_thread_1(self):
        """thread for the first algorythm"""
        dir_name = filedialog.askdirectory(parent=self, initialdir="/",
                                           title='Please select a directory')

        if dir_name != "":
            self.disable_menu()
            self.path_and_bag.check_if_refresh(dir_name)
            self.config(cursor="wait")
            self.update()
            self.clean_queue()
            GUI.static_queue.put("Finding files in chosen folder:\n\n")
            num_files = len([val for sub_list in
                             [[os.path.join(i[0], j)for j in i[2]]
                              for i in os.walk(dir_name)]
                             for val in sub_list])
            rott = tk.Tk()
            app = App(rott, GUI.static_queue, num_files)
            rott.protocol("WM_DELETE_WINDOW", app.on_closing)
            thread = threading.Thread(target=self.open_menu, args=(dir_name,))
            thread.setDaemon(True)
            thread.start()
            app.mainloop()
        else:
            print("Action aborted")

    def open_menu(self, dir_name):
        """select directory with music, alg 1"""
        list_of_songs = []
        self.path_and_bag.clear_bag_of_words()
        for data in os.walk(dir_name):
            for filename in data[2]:
                list_of_songs = self.path_and_bag.change_title(os.path.join(data[0], filename))
                GUI.static_queue.put(filename)
        if not list_of_songs:
            print("action aborted")
        else:
#.........这里部分代码省略.........
开发者ID:Monk-,项目名称:PyMeno,代码行数:103,代码来源:gui.py


注:本文中的tkinter.Listbox.bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。