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


Python Listbox.select_set方法代码示例

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


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

示例1: PRGListBox

# 需要导入模块: from tkinter import Listbox [as 别名]
# 或者: from tkinter.Listbox import select_set [as 别名]
class PRGListBox(Frame):
    def __init__(self, master=None,**args):
        Frame.__init__(self, master,**args)
        scrollbar = Scrollbar(self, orient=VERTICAL) #нужен для отображения длинных списков
        scrollbar.unbind("<Key-Up>")
        scrollbar.unbind("<Key-Down>")
        scrollbar.unbind("<Key-Left>")
        scrollbar.unbind("<Key-Right>")
        scrollbar.pack(side=RIGHT, fill=Y)
        
        self.lst = Listbox(self, yscrollcommand=scrollbar.set, bg="grey", selectmode=SINGLE) 
        self.lst.insert(END,"Hide All")
        self.lst.insert(END,"Show All")
        self.lst.select_set(0)
        self.lst.pack(side=LEFT, fill=BOTH, expand=1)
        
        scrollbar.config(command=self.lst.yview)
开发者ID:sergnov,项目名称:PrgViewer,代码行数:19,代码来源:prgWidgets.py

示例2: InstanceEditor

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

#.........这里部分代码省略.........
            self.typedb.get(), self.namedb.get(), self.userdb.get(), self.pwddb.get())
        security = "MODE=%s" % list(
            self.mode[VALUES]).index(self.mode.get())
        if self.password.get() != '':
            security += ",PASSWORD=%s" % self.password.get()
        module_list = [
            self.module_data[int(item)] for item in self.modules.curselection()]
        appli_id = list(self.applis[VALUES]).index(self.applis.get())
        current_lang = get_locale_lang()
        for lang in DEFAULT_LANGUAGES:
            if lang[1] == self.language.get():
                current_lang = lang[0]
        self.result = (self.name.get(), self.mod_applis[appli_id][
                       0], ",".join(module_list), security, db_param, current_lang)
        self.destroy()

    def _load_current_data(self, instance_name):
        from lucterios.framework.settings import DEFAULT_LANGUAGES, get_locale_lang
        lct_inst = LucteriosInstance(instance_name)
        lct_inst.read()
        self.name.delete(0, END)
        self.name.insert(0, lct_inst.name)
        self.name.config(state=DISABLED)
        applis_id = 0
        for appli_iter in range(len(self.mod_applis)):
            if self.mod_applis[appli_iter][0] == lct_inst.appli_name:
                applis_id = appli_iter
                break
        self.applis.current(applis_id)
        if lct_inst.extra['']['mode'] is not None:
            self.mode.current(lct_inst.extra['']['mode'][0])
        else:
            self.mode.current(2)
        self.mode_selection(None)
        typedb_index = 0
        for typedb_idx in range(len(self.typedb[VALUES])):
            if self.typedb[VALUES][typedb_idx].lower() == lct_inst.database[0].lower():
                typedb_index = typedb_idx
                break
        self.typedb.current(typedb_index)
        self.typedb.config(state=DISABLED)
        self.typedb_selection(None)
        self.namedb.delete(0, END)
        if 'name' in lct_inst.database[1].keys():
            self.namedb.insert(0, lct_inst.database[1]['name'])
        self.userdb.delete(0, END)
        if 'user' in lct_inst.database[1].keys():
            self.userdb.insert(0, lct_inst.database[1]['user'])
        self.pwddb.delete(0, END)
        if 'password' in lct_inst.database[1].keys():
            self.pwddb.insert(0, lct_inst.database[1]['password'])
        self.modules.select_clear(0, self.modules.size())
        for mod_idx in range(len(self.module_data)):
            current_mod = self.module_data[mod_idx]
            if current_mod in lct_inst.modules:
                self.modules.select_set(mod_idx)
        current_lang = get_locale_lang()
        if 'LANGUAGE_CODE' in lct_inst.extra.keys():
            current_lang = lct_inst.extra['LANGUAGE_CODE']
        for lang in DEFAULT_LANGUAGES:
            if lang[0] == current_lang:
                self.language.current(self.language[VALUES].index(lang[1]))

    def execute(self, instance_name=None):
        from lucterios.framework.settings import DEFAULT_LANGUAGES, get_locale_lang
        self.mode[VALUES] = [ugettext(
            "CORE-connectmode.0"), ugettext("CORE-connectmode.1"), ugettext("CORE-connectmode.2")]
        self.language[VALUES] = [lang[1] for lang in DEFAULT_LANGUAGES]
        self.typedb[VALUES] = ["SQLite", "MySQL", "PostgreSQL"]
        lct_glob = LucteriosGlobal()
        _, self.mod_applis, mod_modules = lct_glob.installed()
        self.mod_applis.sort(key=lambda item: get_module_title(item[0]))
        self.modules.delete(0, END)
        self.module_data = []
        module_list = []
        for mod_module_item in mod_modules:
            module_list.append(
                (get_module_title(mod_module_item[0]), mod_module_item[0]))
        module_list.sort(key=lambda module: module[0])
        for module_title, module_name in module_list:
            self.modules.insert(END, module_title)
            self.module_data.append(module_name)
        appli_list = []
        for mod_appli_item in self.mod_applis:
            appli_list.append(get_module_title(mod_appli_item[0]))
        self.applis[VALUES] = appli_list
        if instance_name is not None:
            self._load_current_data(instance_name)
        else:
            self.typedb.current(0)
            self.mode.current(2)
            if len(appli_list) > 0:
                self.applis.current(0)
            self.appli_selection(None)
            self.mode_selection(None)
            self.typedb_selection(None)
            for lang in DEFAULT_LANGUAGES:
                if lang[0] == get_locale_lang():
                    self.language.current(self.language[VALUES].index(lang[1]))
        center(self)
开发者ID:povtux,项目名称:core,代码行数:104,代码来源:lucterios_gui.py

示例3: LintGui

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

#.........这里部分代码省略.........
        self.root.mainloop()

    def quit(self, _=None):
        """quit the application"""
        self.root.quit()

    def halt(self):
        """program halt placeholder"""
        return

    def file_open(self, package=False, _=None):
        """launch a file browser"""
        if not package:
            filename = askopenfilename(parent=self.root, filetypes=[('pythonfiles', '*.py'),
                                                    ('allfiles', '*')], title='Select Module')
        else:
            filename = askdirectory(title="Select A Folder", mustexist=1)

        if filename == ():
            return

        self.txt_module.delete(0, END)
        self.txt_module.insert(0, filename)

    def update_filenames(self):
        """update the list of recent filenames"""
        filename = self.txt_module.get()
        if not filename:
            filename = os.getcwd()
        if filename+'\n' in self.filenames:
            index = self.filenames.index(filename+'\n')
            self.filenames.pop(index)

        #ensure only 10 most recent are stored
        if len(self.filenames) == 10:
            self.filenames.pop()
        self.filenames.insert(0, filename+'\n')

    def set_history_window(self):
        """update the history window with info from the history file"""
        #clear the window
        self.showhistory.delete(0, END)
        # keep the last 10 most recent files
        try:
            view_history = open(HOME+HISTORY, 'r')
            for hist in view_history.readlines():
                if not hist in self.filenames:
                    self.filenames.append(hist)
                self.showhistory.insert(END, hist.split('\n')[0])
            view_history.close()
        except IOError:
            # do nothing since history file will be created later
            return

    def run_lint(self, _=None):
        """launches pylint"""
        self.update_filenames()
        self.root.configure(cursor='watch')
        self.reporter = GUIReporter(self, output=self.report_stream)
        module = self.txt_module.get()
        if not module:
            module = os.getcwd()

        #cleaning up msgs and windows
        self.msgs = []
        self.visible_msgs = []
        self.lb_messages.delete(0, END)
        self.tabs = {}
        self.results.delete(0, END)
        self.btnRun.config(state=DISABLED)

        #setting up a worker thread to run pylint
        worker = Thread(target=lint_thread, args=(module, self.reporter, self,))
        self.periodic_call()
        worker.start()

        # Overwrite the .pylint-gui-history file with all the new recently added files
        # in order from filenames but only save last 10 files
        write_history = open(HOME+HISTORY, 'w')
        write_history.writelines(self.filenames)
        write_history.close()
        self.set_history_window()

        self.root.configure(cursor='')

    def show_sourcefile(self, event=None):
        selected = self.lb_messages.curselection()
        if not selected:
            return

        msg = self.visible_msgs[int(selected[0])]
        scroll = msg.line - 3
        if scroll < 0:
            scroll = 0

        self.tabs["Source File"] = open(msg.path, "r").readlines()
        self.box.set("Source File")
        self.refresh_results_window()
        self.results.yview(scroll)
        self.results.select_set(msg.line - 1)
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:104,代码来源:gui.py

示例4: GUIChecker

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

#.........这里部分代码省略.........
        courses = self.__search_courses(dept_no)
        title = list(courses.columns.values)

        self.__clear_method()
        self.__set_up_tree_widget(title, len(courses))

        for field in title:
            self.tree.heading(field, text=field)
            self.tree.column(field, width=font.Font().measure(field))

        for index, course in courses.iterrows():
            self.tree.insert('', 'end', values=tuple(course.values))
            for ix, val in enumerate(course.values):
                col_w = font.Font().measure(val) + 10
                if self.tree.column(title[ix], width=None) < col_w:
                    self.tree.column(title[ix], width=col_w)

    def __search_courses(self, dept_no):
        crawler = NckuCourseCrawler(dept_no=dept_no)
        html = crawler.get_raw_HTML()
        parser = NckuCourseParser(html)
        parser.include_fields = self.choosen_field
        logging.info("Choosen Field: {}".format(self.choosen_field))
        courses = parser.parse(sort=True)
        print(courses)
        courses['餘額'] = courses['餘額'].apply(int)
        return courses

    def __clear_method(self):
        try:
            self.__remove_tree_widget()
        except Exception as e:
            logging.debug(
                'Widget not yet created. Not and Error. {}'.format(e)
            )

    def __remove_tree_widget(self):
        self.tree_vsb.grid_remove()
        self.tree_hsb.grid_remove()
        self.tree.grid_remove()

    def __set_up_tree_widget(self, title, courses_num):
        tree_height = min(30, courses_num)
        self.tree = ttk.Treeview(columns=title, show="headings",
                                 height=tree_height)
        self.tree_vsb = ttk.Scrollbar(orient="vertical",
                                      command=self.tree.yview)
        self.tree_hsb = ttk.Scrollbar(orient="horizontal",
                                      command=self.tree.xview)
        self.tree.configure(yscrollcommand=self.tree_vsb.set,
                            xscrollcommand=self.tree_hsb.set)

        self.tree.grid(row=3, column=0)
        self.tree_vsb.grid(row=3, column=1, sticky="ns")
        self.tree_hsb.grid(row=4, column=0, sticky="we")

    def __setting_method(self):
        if not self.setting_on:
            self.setting_on = True

            self.setting_win = Toplevel(self)
            self.setting_win.wm_title("Settings")
            self.__create_setting_win_widget()

    def __create_setting_win_widget(self):
        choose_field_label = Label(self.setting_win, text="選擇欄位")
        self.__create_choose_field_listbox()
        confirm_btn = Button(self.setting_win, text="確定", command=self.__confirm_setting)
        default_btn = Button(self.setting_win, text="回復預設值", command=self.__restore_setting)

        confirm_btn.grid(row=0, column=0)
        default_btn.grid(row=0, column=1)
        choose_field_label.grid(row=1, column=0)

    def __create_choose_field_listbox(self):
        self.choose_field_listbox = Listbox(self.setting_win,
                                            selectmode=MULTIPLE,
                                            height=len(self.ALL_FIELDS))
        for i in self.ALL_FIELDS:
            self.choose_field_listbox.insert(END, i)
        for index, choosen in enumerate(self.choosen_field):
            if choosen:
                self.choose_field_listbox.select_set(index)

        self.choose_field_listbox.grid(row=1, column=1, sticky="nsew")

    def __confirm_setting(self):
        print(self.choose_field_listbox)
        print(self.choose_field_listbox.curselection())
        selections = self.choose_field_listbox.curselection()
        self.choosen_field = [
            self.ALL_FIELDS[col_index] for col_index in selections
        ]
        self.setting_win.withdraw()
        self.setting_on = False

    def __restore_setting(self):
        self.choose_field_listbox.grid_remove()
        self.choosen_field = self.default_choosen_field
        self.__create_choose_field_listbox()
开发者ID:Lee-W,项目名称:NCKU-course-checker,代码行数:104,代码来源:GUI.py


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