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


Python Listbox.config方法代码示例

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


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

示例1: Application

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

示例2: Searcher

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import config [as 别名]
class Searcher(Frame):
    """ Keyword Searcher
    This is a very simple python program, which is designed for finding specified key-word
    in files. Just for fun!
    """
    def __init__(self, master=None, cnf={}, **kwargs):
        super(Searcher, self).__init__(master, cnf, **kwargs)
        self._root_path_var = StringVar()
        self._keyword_var = StringVar(self)
        self._listbox = None
        self._result_queue = None
        self.pack(fill=BOTH, expand=YES, padx=5, pady=5)
        self.make_widgets()
        self._consumer()

        # config for main window
        self.master.title('Keyword Searcher')

    def make_widgets(self):
        frm1 = Frame(self)
        frm1.pack(side=TOP, fill=X)
        Entry(frm1, textvariable=self._root_path_var, font=DEFAULT_FONT).pack(side=LEFT, fill=X, expand=YES)
        Button(frm1, text='Add directory', font=DEFAULT_FONT,
               command=lambda: self._root_path_var.set(askdirectory(title='Add directory'))).pack(side=RIGHT)
        
        frm2 = Frame(self)
        frm2.pack(side=TOP, fill=X)
        keyword_ent = Entry(frm2, textvariable=self._keyword_var, font=DEFAULT_FONT)
        keyword_ent.pack(side=LEFT, fill=X, expand=YES)
        Button(frm2, text='Find', font=DEFAULT_FONT, command=self.find).pack(side=RIGHT)

        vs = Scrollbar(self)
        hs = Scrollbar(self)
        self._listbox = Listbox(self)
        vs.pack(side=RIGHT, fill=Y)
        vs.config(command=self._listbox.yview)
        hs.pack(side=BOTTOM, fill=X)
        hs.config(command=self._listbox.xview, orient='horizontal')
        self._listbox.config(yscrollcommand=vs.set, xscrollcommand=hs.set,
                             font=DEFAULT_FONT)
        self._listbox.pack(fill=BOTH, expand=YES)
        self._listbox.bind('<Double-1>', self._navigate_to)

    def find(self):
        self._result_queue = queue.Queue()
        self._listbox.delete('0', 'end')
        Thread(target=self._find, args=(self._root_path_var.get(),
                                        self._keyword_var.get()), daemon=True).start()

    def _find(self, path, keyword):
        if not os.path.exists(path):
            return None

        for this_dir, sub_dirs, files in os.walk(path):
            for file in files:
                file_type = guess_type(file)[0]
                if file_type and 'text' in file_type:
                    fp = os.path.join(this_dir, file)
                    self._result_queue.put(fp) if keyword in open(fp).read() else None

    def _consumer(self):
        if self._result_queue:
            try:
                fp = self._result_queue.get(block=False)
            except queue.Empty:
                pass
            else:
                self._listbox.insert('end', fp)
                # auto scroll.
                self._listbox.yview('end')

        self.after(100, self._consumer)

    def _navigate_to(self, event):
        """
        Only works on Ubuntu platform currently.
        Double click to navigate to selected path.
        It's a very convenient function.
        :return: None
        """
        print(event)
        # get active item from listbox
        path = self._listbox.get('active')
        print(path)

        # open nautilus with param path, before that, check your platform.
        if 'ubuntu' in (os.popen('uname -a').read()).lower():
            os.system('/usr/bin/nautilus {}'.format(path))
        else:
            pass
开发者ID:jiangbingo,项目名称:utilities-python,代码行数:92,代码来源:searcher.py

示例3: RecursiveDescentApp

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import config [as 别名]
class RecursiveDescentApp(object):
    """
    A graphical tool for exploring the recursive descent parser.  The tool
    displays the parser's tree and the remaining text, and allows the
    user to control the parser's operation.  In particular, the user
    can expand subtrees on the frontier, match tokens on the frontier
    against the text, and backtrack.  A "step" button simply steps
    through the parsing process, performing the operations that
    ``RecursiveDescentParser`` would use.
    """
    def __init__(self, grammar, sent, trace=0):
        self._sent = sent
        self._parser = SteppingRecursiveDescentParser(grammar, trace)

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

        # Set up key bindings.
        self._init_bindings()

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

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

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

        # 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)

        # Initialize the parser.
        self._parser.initialize(self._sent)

        # Resize callback
        self._canvas.bind('<Configure>', self._configure)

    #########################################
    ##  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())
        if self._size.get() < 0: big = self._size.get()-2
        else: big = self._size.get()+2
        self._bigfont = tkinter.font.Font(family='helvetica', weight='bold',
                                    size=big)

    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 Expansions')
        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 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)
#.........这里部分代码省略.........
开发者ID:BohanHsu,项目名称:developer,代码行数:103,代码来源:rdparser_app.py

示例4: ShiftReduceApp

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import config [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

示例5: ListboxVidget

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

#.........这里部分代码省略.........
        # Active item background color
        self._active_fg = active_fg

        # Active item foreground color
        self._active_bg = active_bg

        # Selected item background color
        self._selected_fg = selected_fg

        # Selected item foreground color
        self._selected_bg = selected_bg

        # Whether the listbox is changing
        self._is_changing = False

        # Active index. `-1` means void, i.e. no item is active.
        self._indexcur = -1

        # Whether active index is being reset to same value
        self._is_resetting = False

        # Create listbox widget
        self._listbox = Listbox(
            master=self.widget(),
            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
开发者ID:AoiKuiyuyou,项目名称:AoikRegistryEditor,代码行数:70,代码来源:listbox.py

示例6: __init__

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

	def __init__(self, parent, listEntries, guiPrompt, allowManualFolderSelection, forceFolderOnlyChoosing=False):
		"""
		NOTE: do not call this constructor directly. Use the ListChooserDialog.showDialog function instead.
		"""
		self.forceFolderOnlyChoosing = forceFolderOnlyChoosing

		self.top = tkinter.Toplevel(parent)
		defaultPadding = {"padx":20, "pady":10}

		# Set a description for this dialog (eg "Please choose a game to mod"
		tkinter.Label(self.top, text=guiPrompt).pack()

		# Define the main listbox to hold the choices given by the 'listEntries' parameter
		listboxFrame = tkinter.Frame(self.top)

		# Define a scrollbar and a listbox. The yscrollcommand is so that the listbox can control the scrollbar
		scrollbar = tkinter.Scrollbar(listboxFrame, orient=tkinter.VERTICAL)
		self.listbox = Listbox(listboxFrame, selectmode=tkinter.BROWSE, yscrollcommand=scrollbar.set)

		# Also configure the scrollbar to control the listbox, and pack it
		scrollbar.config(command=self.listbox.yview)
		scrollbar.pack(side=tkinter.RIGHT, fill=tkinter.Y)

		# Setting width to 0 forces auto-resize of listbox see: https://stackoverflow.com/a/26504193/848627
		for item in listEntries:
			self.listbox.insert(tkinter.END, item)
		self.listbox.config(width=0)
		self.listbox.pack(side=tkinter.LEFT, fill=tkinter.BOTH, expand=1)

		# Finally, pack the Frame so its contents are displayed on the dialog
		listboxFrame.pack(**defaultPadding)

		# If the user is allowed to choose a directory manually, add directory chooser button
		if allowManualFolderSelection:
			b2 = tkinter.Button(self.top, text="Choose Folder Manually", command=self.showDirectoryChooser)
			b2.pack(**defaultPadding)

		# Add an 'OK' button. When pressed, the dialog is closed
		b = tkinter.Button(self.top, text="OK", command=self.ok)
		b.pack(**defaultPadding)

		# This variable stores the returned value from the dialog
		self.result = None

	def showDirectoryChooser(self):
		if IS_MAC and not self.forceFolderOnlyChoosing:
			self.result = filedialog.askopenfilename(filetypes=[(None, "com.apple.application")])
		else:
			self.result = filedialog.askdirectory()
		self.top.destroy()

	def ok(self):
		"""
		This function is called when the 'OK' button is pressed. It retrieves the value of the currently selected item,
		then closes the dialog
		:return:
		"""
		selected_value = None

		if len(self.listbox.curselection()) > 0:
			selected_index = self.listbox.curselection()[0]
			selected_value = self.listbox.get(selected_index)

		self.result = selected_value

		self.top.destroy()

	@staticmethod
	def showDialog(rootGUIWindow, choiceList, guiPrompt, allowManualFolderSelection, forceFolderOnlyChoosing=False):
		"""
		Static helper function to show dialog and get a return value. Arguments are the same as constructor
		:param rootGUIWindow: the parent tkinter object of the dialog (can be root window)
		:param choiceList: a list of strings that the user is to choose from
		:param guiPrompt: the description that will be shown on the dialog
		:param allowManualFolderSelection: if true, user is allowed to select a folder manually.
		:return: returns the value the user selected (string), or None if none available
		"""
		d = ListChooserDialog(rootGUIWindow, choiceList, guiPrompt, allowManualFolderSelection, forceFolderOnlyChoosing)
		rootGUIWindow.wait_window(d.top)
		return d.result
开发者ID:07th-mod,项目名称:resources,代码行数:84,代码来源:higurashiInstaller.py

示例7: LogUI

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import config [as 别名]
class LogUI(Frame):
  
    def __init__(self, parent):
        Frame.__init__(self, parent)   
        self.parent = parent
        
        self.filemodels = []
        filemodel1 = FileModel("C:/Users/chen_xi/test1.csv", searchconds=[], relation="and", joincondtuples=[])
        filemodel2 = FileModel("C:/Users/chen_xi/test2.csv", searchconds=[], relation="and", joincondtuples=[])
        self.filemodels = [filemodel1, filemodel2]
        
        self._initUI()
        self.selectedfileindex = -1
        
        
    def _initUI(self):
        self.parent.title("Log Processor")
        self.pack()
        
        self._initfilepanel()
        self._initsearchcondpanel()
        self._initjoincondpanel()
        self._initconsole()
        
        self._inflatefilelist()
        
        
    def _initfilepanel(self):
        frame = Frame(self)
        frame.grid(row=0, column=0, sticky=E + W + S + N)
        
        label = Label(frame, text="File List: ")
        label.grid(sticky=N + W)
        
        self.filelist = Listbox(frame, width=40)
        self.filelist.grid(row=1, column=0, rowspan=2, columnspan=3)
        
        vsl = Scrollbar(frame, orient=VERTICAL)
        vsl.grid(row=1, column=3, rowspan=2, sticky=N + S + W)
        
        hsl = Scrollbar(frame, orient=HORIZONTAL)
        hsl.grid(row=3, column=0, columnspan=3, sticky=W + E + N)
        
        self.filelist.config(yscrollcommand=vsl.set, xscrollcommand=hsl.set)
        self.filelist.bind('<<ListboxSelect>>', self._onfilelistselection)
        
        hsl.config(command=self.filelist.xview)
        vsl.config(command=self.filelist.yview)
        
        upbtn = Button(frame, text="Up", width=7, command=self._upfile)
        upbtn.grid(row=1, column=4, padx=5, pady=5)
        
        downbtn = Button(frame, text="Down", width=7, command=self._downfile)
        downbtn.grid(row=2, column=4, padx=5, pady=5)
        
        newbtn = Button(frame, text="New", width=7, command=self._addfile)
        newbtn.grid(row=4, column=1, pady=5, sticky=E + S)
        
        delbtn = Button(frame, text="Delete", width=7, command=self._deletefile)
        delbtn.grid(row=4, column=2, padx=5, pady=5, sticky=W + S)
        
            
    def _inflatefilelist(self):
        self.filelist.delete(0, END)
        for filemodel in self.filemodels:
            self.filelist.insert(END, filemodel.filename)
            
        
    def _initsearchcondpanel(self):
        frame = Frame(self)
        frame.grid(row=0, column=1, sticky=E + W + S + N, padx=5)
        
        label = Label(frame, text="Search Condition: ")
        label.grid(row=0, column=0, columnspan=1, sticky=W)
        
        relationlable = Label(frame, text="Relation")
        relationlable.grid(row=0, column=1, columnspan=1, sticky=E)
        
        self.condrelationvar = StringVar(frame)
        relationinput = Combobox(frame, textvariable=self.condrelationvar, values=["and", "or"])
        relationinput.grid(row=0, column=2, padx=5, sticky=E)
        relationinput.bind('<<ComboboxSelected>>', self._onrelationchange)
        
        self.searchcondlist = Listbox(frame)
        self.searchcondlist.grid(row=1, rowspan=1, columnspan=3, sticky=E + W + S + N)
        
        vsl = Scrollbar(frame, orient=VERTICAL)
        vsl.grid(row=1, column=3, rowspan=1, sticky=N + S + W)
        
        hsl = Scrollbar(frame, orient=HORIZONTAL)
        hsl.grid(row=2, column=0, columnspan=3, sticky=W + E + N)
        
        self.searchcondlist.config(yscrollcommand=vsl.set, xscrollcommand=hsl.set)
        
        hsl.config(command=self.searchcondlist.xview)
        vsl.config(command=self.searchcondlist.yview)
        
        newbtn = Button(frame, text="New", width=7, command=self._addsearchcondition)
        newbtn.grid(row=3, column=0, padx=5, pady=5, sticky=E)
        
#.........这里部分代码省略.........
开发者ID:shawncx,项目名称:LogParser,代码行数:103,代码来源:logui.py

示例8: LucteriosMainForm

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import config [as 别名]
class LucteriosMainForm(Tk):

    def __init__(self):
        Tk.__init__(self)
        try:
            img = Image("photo", file=join(
                dirname(import_module('lucterios.install').__file__), "lucterios.png"))
            self.tk.call('wm', 'iconphoto', self._w, img)
        except:
            pass
        self.has_checked = False
        self.title(ugettext("Lucterios installer"))
        self.minsize(475, 260)
        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)
        self.running_instance = {}
        self.resizable(True, True)
        self.protocol("WM_DELETE_WINDOW", self.on_closing)

        self.ntbk = ttk.Notebook(self)
        self.ntbk.grid(row=0, column=0, columnspan=1, sticky=(N, S, E, W))

        self.create_instance_panel()
        self.create_module_panel()

        stl = ttk.Style()
        stl.theme_use("default")
        stl.configure("TProgressbar", thickness=5)
        self.progress = ttk.Progressbar(
            self, style="TProgressbar", orient='horizontal', mode='indeterminate')
        self.progress.grid(row=1, column=0, sticky=(E, W))

        self.btnframe = Frame(self, bd=1)
        self.btnframe.grid(row=2, column=0, columnspan=1)
        Button(self.btnframe, text=ugettext("Refresh"), width=20, command=self.refresh).grid(
            row=0, column=0, padx=3, pady=3, sticky=(N, S))
        self.btnupgrade = Button(
            self.btnframe, text=ugettext("Search upgrade"), width=20, command=self.upgrade)
        self.btnupgrade.config(state=DISABLED)
        self.btnupgrade.grid(row=0, column=1, padx=3, pady=3, sticky=(N, S))
        Button(self.btnframe, text=ugettext("Close"), width=20, command=self.on_closing).grid(
            row=0, column=2, padx=3, pady=3, sticky=(N, S))

    def on_closing(self):
        all_stop = True
        instance_names = list(self.running_instance.keys())
        for old_item in instance_names:
            if (self.running_instance[old_item] is not None) and self.running_instance[old_item].is_running():
                all_stop = False
        if all_stop or askokcancel(None, ugettext("An instance is always running.\nDo you want to close?")):
            self.destroy()
        else:
            self.refresh()

    def destroy(self):
        instance_names = list(self.running_instance.keys())
        for old_item in instance_names:
            if self.running_instance[old_item] is not None:
                self.running_instance[old_item].stop()
                del self.running_instance[old_item]
        Tk.destroy(self)

    def create_instance_panel(self):
        frm_inst = Frame(self.ntbk)
        frm_inst.grid_columnconfigure(0, weight=1)
        frm_inst.grid_rowconfigure(0, weight=1)
        frm_inst.grid_columnconfigure(1, weight=3)
        frm_inst.grid_rowconfigure(1, weight=0)
        self.instance_list = Listbox(frm_inst, width=20)
        self.instance_list.bind('<<ListboxSelect>>', self.select_instance)
        self.instance_list.pack()
        self.instance_list.grid(row=0, column=0, sticky=(N, S, W, E))

        self.instance_txt = Text(frm_inst, width=75)
        self.instance_txt.grid(row=0, column=1, rowspan=2, sticky=(N, S, W, E))
        self.instance_txt.config(state=DISABLED)

        self.btninstframe = Frame(frm_inst, bd=1)
        self.btninstframe.grid(row=1, column=0, columnspan=1)
        self.btninstframe.grid_columnconfigure(0, weight=1)
        Button(self.btninstframe, text=ugettext("Launch"), width=25, command=self.open_inst).grid(
            row=0, column=0, columnspan=2, sticky=(N, S))
        Button(self.btninstframe, text=ugettext("Modify"), width=10,
               command=self.modify_inst).grid(row=1, column=0, sticky=(N, S))
        Button(self.btninstframe, text=ugettext("Delete"), width=10,
               command=self.delete_inst).grid(row=1, column=1, sticky=(N, S))
        Button(self.btninstframe, text=ugettext("Save"), width=10,
               command=self.save_inst).grid(row=2, column=0, sticky=(N, S))
        Button(self.btninstframe, text=ugettext("Restore"), width=10,
               command=self.restore_inst).grid(row=2, column=1, sticky=(N, S))
        Button(self.btninstframe, text=ugettext("Add"), width=25, command=self.add_inst).grid(
            row=3, column=0, columnspan=2, sticky=(N, S))

        self.ntbk.add(frm_inst, text=ugettext('Instances'))

    def create_module_panel(self):
        frm_mod = Frame(self.ntbk)
        frm_mod.grid_columnconfigure(0, weight=1)
        frm_mod.grid_rowconfigure(0, weight=1)
        self.module_txt = Text(frm_mod)
#.........这里部分代码省略.........
开发者ID:povtux,项目名称:core,代码行数:103,代码来源:lucterios_gui.py

示例9: DrtGlueDemo

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import config [as 别名]
class DrtGlueDemo(object):
    def __init__(self, examples):
        # Set up the main window.
        self._top = Tk()
        self._top.title("DRT Glue Demo")

        # Set up key bindings.
        self._init_bindings()

        # Initialize the fonts.self._error = None
        self._init_fonts(self._top)

        self._examples = examples
        self._readingCache = [None for example in examples]

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

        # Set the data to None
        self._curExample = -1
        self._readings = []
        self._drs = None
        self._drsWidget = None
        self._error = None

        self._init_glue()

        # Create the basic frames.
        self._init_menubar(self._top)
        self._init_buttons(self._top)
        self._init_exampleListbox(self._top)
        self._init_readingListbox(self._top)
        self._init_canvas(self._top)

        # Resize callback
        self._canvas.bind("<Configure>", self._configure)

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

    def _init_glue(self):
        tagger = RegexpTagger(
            [
                ("^(David|Mary|John)$", "NNP"),
                ("^(walks|sees|eats|chases|believes|gives|sleeps|chases|persuades|tries|seems|leaves)$", "VB"),
                ("^(go|order|vanish|find|approach)$", "VB"),
                ("^(a)$", "ex_quant"),
                ("^(every)$", "univ_quant"),
                ("^(sandwich|man|dog|pizza|unicorn|cat|senator)$", "NN"),
                ("^(big|gray|former)$", "JJ"),
                ("^(him|himself)$", "PRP"),
            ]
        )

        depparser = MaltParser(tagger=tagger)
        self._glue = DrtGlue(depparser=depparser, remove_duplicates=False)

    def _init_fonts(self, root):
        # See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
        self._sysfont = 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 = Font(family="helvetica", weight="bold", size=self._size.get())
        self._font = Font(family="helvetica", size=self._size.get())
        if self._size.get() < 0:
            big = self._size.get() - 2
        else:
            big = self._size.get() + 2
        self._bigfont = Font(family="helvetica", weight="bold", size=big)

    def _init_exampleListbox(self, parent):
        self._exampleFrame = listframe = Frame(parent)
        self._exampleFrame.pack(fill="both", side="left", padx=2)
        self._exampleList_label = Label(self._exampleFrame, font=self._boldfont, text="Examples")
        self._exampleList_label.pack()
        self._exampleList = Listbox(
            self._exampleFrame,
            selectmode="single",
            relief="groove",
            background="white",
            foreground="#909090",
            font=self._font,
            selectforeground="#004040",
            selectbackground="#c0f0c0",
        )

        self._exampleList.pack(side="right", fill="both", expand=1)

        for example in self._examples:
            self._exampleList.insert("end", ("  %s" % example))
        self._exampleList.config(height=min(len(self._examples), 25), width=40)

        # Add a scrollbar if there are more than 25 examples.
        if len(self._examples) > 25:
#.........这里部分代码省略.........
开发者ID:BRISATECH,项目名称:ResumeManagementTool,代码行数:103,代码来源:drt_glue_demo.py

示例10: GetKeysDialog

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import config [as 别名]
class GetKeysDialog(Toplevel):

    # Dialog title for invalid key sequence
    keyerror_title = 'Key Sequence Error'

    def __init__(self, parent, title, action, current_key_sequences,
                 *, _htest=False, _utest=False):
        """
        parent - parent of this dialog
        title - string which is the title of the popup dialog
        action - string, the name of the virtual event these keys will be
                 mapped to
        current_key_sequences - list, a list of all key sequence lists
                 currently mapped to virtual events, for overlap checking
        _htest - bool, change box location when running htest
        _utest - bool, do not wait when running unittest
        """
        Toplevel.__init__(self, parent)
        self.withdraw()  # Hide while setting geometry.
        self.configure(borderwidth=5)
        self.resizable(height=False, width=False)
        self.title(title)
        self.transient(parent)
        self.grab_set()
        self.protocol("WM_DELETE_WINDOW", self.cancel)
        self.parent = parent
        self.action = action
        self.current_key_sequences = current_key_sequences
        self.result = ''
        self.key_string = StringVar(self)
        self.key_string.set('')
        # Set self.modifiers, self.modifier_label.
        self.set_modifiers_for_platform()
        self.modifier_vars = []
        for modifier in self.modifiers:
            variable = StringVar(self)
            variable.set('')
            self.modifier_vars.append(variable)
        self.advanced = False
        self.create_widgets()
        self.update_idletasks()
        self.geometry(
                "+%d+%d" % (
                    parent.winfo_rootx() +
                    (parent.winfo_width()/2 - self.winfo_reqwidth()/2),
                    parent.winfo_rooty() +
                    ((parent.winfo_height()/2 - self.winfo_reqheight()/2)
                    if not _htest else 150)
                ) )  # Center dialog over parent (or below htest box).
        if not _utest:
            self.deiconify()  # Geometry set, unhide.
            self.wait_window()

    def showerror(self, *args, **kwargs):
        # Make testing easier.  Replace in #30751.
        messagebox.showerror(*args, **kwargs)

    def create_widgets(self):
        self.frame = frame = Frame(self, borderwidth=2, relief='sunken')
        frame.pack(side='top', expand=True, fill='both')

        frame_buttons = Frame(self)
        frame_buttons.pack(side='bottom', fill='x')

        self.button_ok = Button(frame_buttons, text='OK',
                                width=8, command=self.ok)
        self.button_ok.grid(row=0, column=0, padx=5, pady=5)
        self.button_cancel = Button(frame_buttons, text='Cancel',
                                   width=8, command=self.cancel)
        self.button_cancel.grid(row=0, column=1, padx=5, pady=5)

        # Basic entry key sequence.
        self.frame_keyseq_basic = Frame(frame, name='keyseq_basic')
        self.frame_keyseq_basic.grid(row=0, column=0, sticky='nsew',
                                      padx=5, pady=5)
        basic_title = Label(self.frame_keyseq_basic,
                            text=f"New keys for '{self.action}' :")
        basic_title.pack(anchor='w')

        basic_keys = Label(self.frame_keyseq_basic, justify='left',
                           textvariable=self.key_string, relief='groove',
                           borderwidth=2)
        basic_keys.pack(ipadx=5, ipady=5, fill='x')

        # Basic entry controls.
        self.frame_controls_basic = Frame(frame)
        self.frame_controls_basic.grid(row=1, column=0, sticky='nsew', padx=5)

        # Basic entry modifiers.
        self.modifier_checkbuttons = {}
        column = 0
        for modifier, variable in zip(self.modifiers, self.modifier_vars):
            label = self.modifier_label.get(modifier, modifier)
            check = Checkbutton(self.frame_controls_basic,
                                command=self.build_key_string, text=label,
                                variable=variable, onvalue=modifier, offvalue='')
            check.grid(row=0, column=column, padx=2, sticky='w')
            self.modifier_checkbuttons[modifier] = check
            column += 1

#.........这里部分代码省略.........
开发者ID:Eyepea,项目名称:cpython,代码行数:103,代码来源:config_key.py

示例11: App

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import config [as 别名]
class App(Frame):
    version = "0.1"
    padding = 10
    screenWidth = 800
    screenHeight = 600

    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.parent = parent

        self.py = pydle()

        self._initUI()

    def _initUI(self):
        self.parent.title("Pydle v" + self.version)
        self.parent.minsize(width=str(self.screenWidth), height=str(self.screenHeight))
        # self.parent.config(border=0)

        # Styles
        style = Style()
        style.configure("TFrame", background="gray", border=0)
        style.configure("TButton", background="gray", foreground="lightgray", highlightforeground="black", highlightbackground="darkgray", compound=RIGHT, relief=FLAT)

        self.config(style="TFrame")
        self.pack(fill=BOTH, expand=1)

        # Menus
        mnuBar = Menu(self.parent)
        self.parent.config(menu=mnuBar)

        mnuFile = Menu(mnuBar, background="gray")
        mnuFile.add_command(label="Exit", command=self.onExitMnu)
        mnuBar.add_cascade(label="File", menu=mnuFile)

        mnuHelp = Menu(mnuBar, background="gray")
        mnuHelp.add_command(label="About", command=self.onAboutMnu)
        mnuBar.add_cascade(label="Help", menu=mnuHelp)

        # Frame content
        frmBooks = Frame(self, style="TFrame")
        frmBooks.pack(side=LEFT, anchor=N+W, fill=BOTH, expand=1, padx=(self.padding, self.padding / 2), pady=self.padding)

        self.lstBooks = Listbox(frmBooks)
        self.lstBooks.config(background="lightgray", foreground="black", borderwidth=0)
        self.lstBooks.pack(fill=BOTH, expand=1)

        frmButtons = Frame(self)
        frmButtons.pack(anchor=N+E, padx=(self.padding / 2, self.padding), pady=self.padding)

        btnLoadBooks = Button(frmButtons, text="Load Books", style="TButton", command=self.onLoadBooksBtn)
        btnLoadBooks.pack(side=TOP, fill=X)

        btnGetNotes = Button(frmButtons, text="Get Notes", style="TButton", command=self.onGetNotesBtn)
        btnGetNotes.pack(side=TOP, fill=X)

        btnBackupBook = Button(frmButtons, text="Backup Book", style="TButton", command=self.onBackupBtn)
        btnBackupBook.pack(side=TOP, fill=X)

        btnBackupAllBooks = Button(frmButtons, text="Backup All Books", style="TButton", command=self.onBackupAllBtn)
        btnBackupAllBooks.pack(side=TOP, fill=X)

    def onLoadBooksBtn(self):
        books = self.py.getBooks()

        for book in books:
            self.lstBooks.insert(END, book["name"])

    def onBackupBtn(self):
        pass

    def onBackupAllBtn(self):
        pass

    def onGetNotesBtn(self):
        notes = self.py.getNotes()

        for note in notes:
            self.lstBooks.insert(END, note)

    def onAboutMnu(self):
        pass

    def onExitMnu(self):
        self.onExit()

    def onExit(self):
        self.quit()
开发者ID:claudemuller,项目名称:pydle,代码行数:90,代码来源:app.py

示例12: __init__

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import config [as 别名]
class SpeciesSearchDialog:
    def __init__(self, parent, caller):
        # main window
        self.parent = parent
        # dialog that called this second dialog
        self.caller = caller
        self.gui = Toplevel(parent.guiRoot)
        self.gui.grab_set()
        self.gui.focus()

        self.gui.columnconfigure(0, weight=1)
        self.gui.rowconfigure(1, weight=1)

        self.entrySearch = Entry(self.gui)

        self.buttonSearch = Button(self.gui, text=" Search ")
        self.buttonAdd = Button(self.gui, text=" Add Species ")
        self.buttonClose = Button(self.gui, text=" Close Window ")

        self.frameResults = Frame(self.gui)
        self.frameResults.columnconfigure(0, weight=1)
        self.frameResults.rowconfigure(0, weight=1)
        self.scrollResults = Scrollbar(self.frameResults, orient="vertical")
        self.scrollResults.grid(row=0, column=1, sticky="ns")
        self.listResults = Listbox(self.frameResults, width=70, height=20)
        self.listResults.grid(row=0, column=0, sticky="nswe")

        self.listResults.config(yscrollcommand=self.scrollResults.set)
        self.scrollResults.config(command=self.listResults.yview)

        self.entrySearch.grid(row=0, column=0, columnspan=2, sticky="we", padx=5, pady=5)
        self.frameResults.grid(row=1, column=0, columnspan=3, sticky="nswe", padx=5, pady=5)
        self.buttonSearch.grid(row=0, column=2, padx=5, pady=5, sticky="e")
        self.buttonAdd.grid(row=2, column=1, padx=5, pady=5, sticky="e")
        self.buttonClose.grid(row=2, column=2, padx=5, pady=5, sticky="e")

        self.gui.protocol("WM_DELETE_WINDOW", self.actionClose)
        self.buttonClose.bind("<ButtonRelease>", self.actionClose)
        self.buttonAdd.bind("<ButtonRelease>", self.actionAdd)
        self.buttonSearch.bind("<ButtonRelease>", self.actionSearch)
        self.entrySearch.bind("<Return>", self.actionSearch)

        self.gui.update()
        self.gui.minsize(self.gui.winfo_width(), self.gui.winfo_height())

        self.gui.mainloop()

    def actionAdd(self, event):
        try:
            selection = self.listResults.selection_get()
            selectionSplit = selection.split(":\t", 1)
            selectionSplit2 = selectionSplit[1].split("\t")
            if not (selectionSplit[0], selectionSplit2[0]) in self.parent.optimizer.speciesList:
                self.parent.optimizer.speciesList.append((selectionSplit[0], selectionSplit2[0].strip()))
            self.caller.gui.event_generate("<<Update>>")
        except tkinter.TclError:
            # no selection
            pass

    def actionSearch(self, event):
        query = self.entrySearch.get()
        if query:

            self.listResults.delete(0, "end")

            results = self.parent.optimizer.SPSUMHandler.search(query)
            # sort results by nr of CDS
            results = sorted(results.items(), reverse=True, key=lambda x: (int(x[1][1])))
            for name, (taxid, ncs) in results:
                self.listResults.insert("end", taxid + ":\t " + name + " \t(" + ncs + " CDS)")

    def actionClose(self, event=None):
        self.caller.gui.event_generate("<<Update>>", when="tail")
        self.gui.destroy()
开发者ID:hoerldavid,项目名称:codonoptimizer,代码行数:76,代码来源:OptimizerMainWindow.py

示例13: Application

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


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