python类Combobox()的实例源码

choicebook.py 文件源码 项目:pkinter 作者: DeflatedPickle 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, parent, combobox_position="top", *args):
        ttk.Frame.__init__(self, parent, *args)
        self.parent = parent
        self._combobox_position = combobox_position

        self._page_list = []
        self._label_list = []

        self._variable = tk.StringVar()

        self._combobox = ttk.Combobox(self, state="readonly", textvariable=self._variable)
        self._combobox.pack(side=combobox_position, fill="x")
        self._combobox.bind("<<ComboboxSelected>>", self._change_page, "+")

        self.frame = ttk.Frame(self)
        self.frame.pack(fill="both", expand=True)
references.py 文件源码 项目:Colony 作者: DeflatedPickle 项目源码 文件源码 阅读 51 收藏 0 点赞 0 评论 0
def __init__(self, parent, option, **kwargs):
        ttk.Frame.__init__(self, parent, **kwargs)
        self.parent = parent
        self.option = option

        # TODO: Add more options.

        ttk.Checkbutton(self, text="Debugging Mode", variable=self.option.variable_debug).grid(row=0, column=0, sticky="we")
        ttk.Checkbutton(self, text="Scrollbars", variable=self.option.variable_scrollbars).grid(row=1, column=0, sticky="we")
        ttk.Checkbutton(self, text="Grid", variable=self.option.variable_grid).grid(row=2, column=0, sticky="we")
        ttk.Checkbutton(self, text="Grid Highlight", variable=self.option.variable_grid_highlight).grid(row=3, column=0, sticky="we")

        frame_colour = ttk.Frame(self)
        ttk.Label(frame_colour, text="Highlight Colour").grid(row=0, column=0)
        ttk.Combobox(frame_colour, textvariable=self.option.variable_highlight_colour, values=["white", "red", "blue", "yellow", "green", "purple", "orange", "pink"], state="readonly", width=7).grid(row=0, column=1)
        frame_colour.grid(row=4, column=0, sticky="we")

        ttk.Checkbutton(self, text="Extra Speed Arrows", variable=self.option.variable_extra_speed_arrows).grid(row=5, column=0, sticky="we")
settings.py 文件源码 项目:porcupine 作者: Akuli 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def add_combobox(self, key, choices, text, *, case_sensitive=True):
        """Add a ``ttk.Combobox`` that sets an option to a string.

        The combobox will contain each string in *choices*.

        A `validator callback <Validating>`_ that ensures the value is
        in *choices* is also added. If *case_sensitive* is False,
        :meth:`str.casefold` is used when comparing the strings.
        """
        def validator(value):
            if case_sensitive:
                ok = (value in choices)
            else:
                ok = (value.casefold() in map(str.casefold, choices))
            if not ok:
                raise InvalidValue("%r is not a valid %r value"
                                   % (value, key))

        self.connect(key, validator)

        frame = self.add_frame(key)
        ttk.Label(frame, text=text).pack(side='left')
        ttk.Combobox(frame, values=choices,
                     textvariable=self.get_var(key)).pack(side='right')
GUI.py 文件源码 项目:Python-GUI-Programming-Cookbook-Second-Edition 作者: PacktPublishing 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def defaultFileEntries(self): 
        self.fileEntry.delete(0, tk.END)
        self.fileEntry.insert(0, 'Z:\\')        # bogus path
        self.fileEntry.config(state='readonly')         

        self.netwEntry.delete(0, tk.END)
        self.netwEntry.insert(0, 'Z:\\Backup')  # bogus path                      

    # Combobox callback
test_widgets.py 文件源码 项目:Craft-Clash 作者: Derpyface-Development-Co 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def create(self, **kwargs):
        return ttk.Combobox(self.root, **kwargs)
test_widgets.py 文件源码 项目:Craft-Clash 作者: Derpyface-Development-Co 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def create(self, **kwargs):
        return ttk.Combobox(self.root, **kwargs)
test_widgets.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def setUp(self):
        support.root_deiconify()
        self.combo = ttk.Combobox()
test_widgets.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_values(self):
        def check_get_current(getval, currval):
            self.assertEqual(self.combo.get(), getval)
            self.assertEqual(self.combo.current(), currval)

        check_get_current('', -1)

        self.combo['values'] = ['a', 1, 'c']

        self.combo.set('c')
        check_get_current('c', 2)

        self.combo.current(0)
        check_get_current('a', 0)

        self.combo.set('d')
        check_get_current('d', -1)

        # testing values with empty string
        self.combo.set('')
        self.combo['values'] = (1, 2, '', 3)
        check_get_current('', 2)

        # testing values with empty string set through configure
        self.combo.configure(values=[1, '', 2])
        self.assertEqual(self.combo['values'], ('1', '', '2'))

        # out of range
        self.assertRaises(tkinter.TclError, self.combo.current,
            len(self.combo['values']))
        # it expects an integer (or something that can be converted to int)
        self.assertRaises(tkinter.TclError, self.combo.current, '')

        # testing creating combobox with empty string in values
        combo2 = ttk.Combobox(values=[1, 2, ''])
        self.assertEqual(combo2['values'], ('1', '2', ''))
        combo2.destroy()
AutoComplete.py 文件源码 项目:FunKii-UI 作者: dojafoja 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def autocomplete(self, delta=0):
                """autocomplete the Combobox, delta may be 0/1/-1 to cycle through possible hits"""
                if delta: # need to delete selection otherwise we would fix the current position
                        self.delete(self.position, tkinter.END)
                else: # set position to end so selection starts where textentry ended
                        self.position = len(self.get())
                # collect hits
                _hits = []
                for element in self._completion_list:

                        box_value = self.get()
                        if element.lower().startswith(box_value.lower()): # Match case insensitively
                                _hits.append(element)
                # if we have a new hit list, keep this in mind
                if _hits != self._hits:
                        self._hit_index = 0
                        self._hits=_hits
                # only allow cycling if we are in a known hit list
                if _hits == self._hits and self._hits:
                        self._hit_index = (self._hit_index + delta) % len(self._hits)
                # now finally perform the auto completion
                if self._hits:
                        txt=self._hits[self._hit_index]
                        self.delete(0,tkinter.END)
                        self.insert(0,txt)
                        self.select_range(self.position,tkinter.END)
                        self.event_generate('<<ComboboxSelected>>')
                else:
                        self.event_generate('<<NoHits>>')
frame_mapping.py 文件源码 项目:qal 作者: OptimalBPM 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def init_widgets(self):

        """Init all widgets"""

        # Source reference
        self.cb_source_ref = ttk.Combobox(self, textvariable=self.src_reference, state='normal')
        self.cb_source_ref['values'] = self.get_source_references()
        self.cb_source_ref.pack(side=LEFT, fill=X, expand=1)


        # Data type label
        self.l_data_type = ttk.Label(self, textvariable=self.src_datatype, width=8)
        self.src_datatype.set("Not set")

        self.l_data_type.pack(side=LEFT)

        # Dest reference
        self.cb_dest_ref = ttk.Combobox(self, textvariable=self.dest_reference, state='normal')
        self.cb_dest_ref['values'] = self.get_destination_references()
        self.cb_dest_ref.pack(side=RIGHT, fill=X, expand=1)

        # Is key field
        self.cb_is_key = ttk.Checkbutton(self, variable=self.is_key)
        self.cb_is_key.pack(side=RIGHT)

        # Current data
        self.l_data = ttk.Label(self, textvariable=self.curr_data)
        self.curr_data.set("No data")
        self.l_data.pack(side=RIGHT, fill=X, padx=5)
frame_dataset_xpath.py 文件源码 项目:qal 作者: OptimalBPM 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def init_widgets(self):
        # file selector
        self.btn_file_select=Button(self, text="Select file",command=self.on_select)
        self.btn_file_select.grid(column=0, row=0, columnspan=2)

        # filename
        self.filename, self.e_filename, self.l_filename = make_entry(self, "File name: ", 1)

        # rows_xpath
        self.rows_xpath, self.e_rows_xpath, self.l_rows_xpath = make_entry(self, "Rows XPath: ", 2)

        # xpath_data_format
        self.xpath_data_format = StringVar()

        self.l_xpath_data_format = ttk.Label(self, text="Data format: :")
        self.l_xpath_data_format.grid(column=0, row=3)

        self.sel_xpath_data_format = ttk.Combobox(self, textvariable=self.xpath_data_format, state='readonly')
        self.sel_xpath_data_format['values'] = ["XML", "HTML"]
        self.sel_xpath_data_format.current(0)
        self.sel_xpath_data_format.grid(column=1, row=3)

        # xpath_text_qualifier
        self.xpath_text_qualifier, self.e_xpath_text_qualifier, self.l_xpath_text_qualifier = make_entry(self, "Text qualifier: ", 4)

        # encoding
        self.encoding, self.e_encoding, self.l_encoding = make_entry(self, "Encoding: ", 5)

        self.field_names = []
        self.field_xpaths = []
        self.field_types = []
jogo_mundo_wumpus.py 文件源码 项目:hunt_the_wumpus 作者: leonardoRampazzo 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def add_posicoes(self):
        self.add_botoes_a_grid()
        self.buttonGO = Button(text="Start :>",command=self.start)
        self.buttonGO.grid(row=5,column=4)

        self.select = ttk.Combobox(width=10,value=['Facil', 'Médio', 'Dificil' , 'impossivel'])
        self.select.set("Facil")
        self.select.bind("<<ComboboxSelected>>", self.execute)
        self.select.state(['readonly'])
        self.select.grid(row=5,column=2)


        self.selectVel = ttk.Combobox(width=10,value=['Devagar', 'Normal', 'Rápido' , 'Flash'])
        self.selectVel.set("Devagar")
        self.selectVel.bind("<<ComboboxSelected>>", self.muda_velocidade)
        self.selectVel.state(['readonly'])
        self.selectVel.grid(row=6,column=2)

        self.label = Label(text="Pontos: 1000")
        self.label.grid(row=5,column=7)

        self.label1 = Label(text="Dificuldade:")
        self.label1.grid(row=5,column=1)

        self.label2 = Label(text="Velocidade:")
        self.label2.grid(row=6,column=1)

        self.text        = Text(height=30,width=50)
        self.text.grid(row=1,column=5,columnspan=3,rowspan=4,padx=5,pady=5)
test_widgets.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def create(self, **kwargs):
        return ttk.Combobox(self.root, **kwargs)
window.py 文件源码 项目:quill 作者: DeflatedPickle 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def insert_ttk_combobox(self, exportselection: bool=False, justify: str="left", height: int=None, postcommand=None, state: str="normal", textvariable: tk.Variable=None, values: list=[], width: int=10, index: int or str="end", *args, **kwargs):
        """Insert a ttk.Combobox into the game."""
        widget = ttk.Combobox(self.text, exportselection=exportselection, justify=justify, height=height, postcommand=postcommand, state=state, textvariable=textvariable, values=values, width=width, **kwargs)
        self.text.window_create(index, window=widget)

        return widget
cfgWindow.py 文件源码 项目:serialplot 作者: crxguy52 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, parent, controller):
        ttk.Frame.__init__(self, parent)
        self.controller = controller
        self['padding'] = [0, 7, 0, 0]

        #Populate the serial configuration tab        
        self.baudlist = (4800, 9600, 19200, 38400, 57600, 115200, 230400, 921600)
        self.databitslist = (7, 8)
        self.stopbitslist = (1, 2)
        self.paritylist = ('None', 'Even', 'Odd', 'Mark', 'Space')

        baudlabel = ttk.Label(self, text='Baudrate')
        baudbox = ttk.Combobox(self, width=8, values=self.baudlist, 
                        textvariable=self.controller.TKvariables['baud'])
        datalabel = ttk.Label(self, text='Data bits')
        databox = ttk.Combobox(self, width=8, values = self.databitslist, \
                        textvariable=self.controller.TKvariables['databits'])            
        stopbitslabel = ttk.Label(self, text='Stop bits')
        stopbitsbox = ttk.Combobox(self, width=8, values=self.stopbitslist, \
                        textvariable=self.controller.TKvariables['stopbits'])          
        paritylabel = ttk.Label(self, text='Parity')
        paritybox = ttk.Combobox(self, width=8, values=self.paritylist, \
                        textvariable=self.controller.TKvariables['parity'])

        #ttk.Label(self, text='            ').grid(row=1, column=0)                
        baudlabel.grid(row=1, column = 1, padx=5)
        baudbox.grid(row=1, column=2, padx=5)
        datalabel.grid(row=2, column = 1, padx=5)
        databox.grid(row=2, column=2,  padx=5)
        stopbitslabel.grid(row=3, column = 1,  padx=5)
        stopbitsbox.grid(row=3, column=2,  padx=5)
        paritylabel.grid(row=4, column = 1,  padx=5)
        paritybox.grid(row=4, column=2,  padx=5)
test_widgets.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def create(self, **kwargs):
        return ttk.Combobox(self.root, **kwargs)
MyTreeview.py 文件源码 项目:stash-scanner 作者: senuido 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def set(self, val):
            if isinstance(self.entry, Combobox):
                self.entry.set(val)
            else:
                self.entry.delete(0, END)
                self.entry.insert(0, val)
gui.py 文件源码 项目:pyTrack 作者: clamytoe 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def setup_tab3(tab):
    # remove frame
    remove_frame = ttk.LabelFrame(tab, text='Remove Project')
    remove_frame.grid(columnspan=2, row=0, padx=5, pady=5, sticky='ew')

    # Remove Project
    project_to_axe = tk.StringVar()

    walking_dead = ttk.Combobox(remove_frame, width=18, textvariable=project_to_axe, state='readonly')
    walking_dead['values'] = PROJECT_NAMES
    walking_dead.grid(columnspan=2, row=0, padx=5, pady=5)
    walking_dead.current(INDEX)
    walking_dead.configure(state='enabled') if PROJECTS else walking_dead.configure(state='disabled')

    # spacer
    spacer_label = ttk.Label(remove_frame, text='')
    spacer_label.grid(columnspan=2, row=1, padx=5, pady=5)

    # add button and commands
    def remove_command():
        choice = PROJECTS[PROJECT_NAMES.index(walking_dead.get())].id
        remove_project(choice, safe=False)
        spacer_label.configure(text='Project was removed!', foreground='green')
        walking_dead.set('')
        init_globals()
        setup_tab1(TAB_1)
        if not PROJECTS:
            walking_dead.configure(state='disabled')
            remove_button.configure(state='disabled')

    remove_button = ttk.Button(tab, text='Remove Project', command=remove_command)
    remove_button.grid(columnspan=2, row=3, pady=5)
    remove_button.configure(state='enabled') if PROJECTS else remove_button.configure(state='disabled')
gui.py 文件源码 项目:tools4dou 作者: anddreiferreira 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __combobox(self):
    self.combobox_value = StringVar()
    self.combobox_gui = ttk.Combobox(self.parent, textvariable=self.combobox_value, state='readonly')
    self.combobox_gui['values'] = ('Selecione...', 'MongoDB', 'Elasticsearch')
    self.combobox_gui.current(0)
    self.combobox_gui.grid(column=1, row=8, sticky=(W, E))
pyCSS.py 文件源码 项目:pyCSS 作者: eamontoyaa 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def wantEvaluateOnlyOneSurfaceActivate():
    if wantEvaluateOnlyOneSurfaceVal.get() == True:
        Entry(slipCircleFrame, width=8, textvariable=\
            hztDistPointAtCrownFromCrownVal, state='normal').place(x=366, y=60)
        Entry(slipCircleFrame, width=8, \
            textvariable=hztDistPointAtToeFromCrownVal, state='normal').place(\
            x=366, y=80)
        Entry(slipCircleFrame, width=8, textvariable=slipRadiusVal, \
            state='normal').place(x=366, y=100) ###---
        Entry(slipCircleFrame, width=8, textvariable=numCirclesVal, \
            state='disabled').place(x=690, y=40)
        Entry(slipCircleFrame, width=8, textvariable=radiusIncrementVal, \
            state='disabled').place(x=690, y=60)
        Entry(slipCircleFrame, width=8, textvariable=numberIncrementsVal, \
            state='disabled').place(x=690, y=80)
        Entry(slipCircleFrame, width=8, textvariable=maxFsValueContVal, \
            state='disabled').place(x=690, y=100) ###---
        ttk.Combobox(values=['Fellenius', 'Bishop', 'Ambos'], state='normal',\
            textvariable=methodStringVal, width=7).place(x=420, y=300)  
    else:
        Entry(slipCircleFrame, width=8, textvariable=\
            hztDistPointAtCrownFromCrownVal, state='disabled').place(\
            x=366, y=60)
        Entry(slipCircleFrame, width=8, \
            textvariable=hztDistPointAtToeFromCrownVal, state='disabled').\
            place(x=366, y=80)
        Entry(slipCircleFrame, width=8, textvariable=slipRadiusVal, \
            state='disabled').place(x=366, y=100) ###---        
        Entry(slipCircleFrame, width=8, textvariable=numCirclesVal, \
            state='normal').place(x=690, y=40)
        Entry(slipCircleFrame, width=8, textvariable=radiusIncrementVal, \
            state='normal').place(x=690, y=60)
        Entry(slipCircleFrame, width=8, textvariable=numberIncrementsVal, \
            state='normal').place(x=690, y=80)
        Entry(slipCircleFrame, width=8, textvariable=maxFsValueContVal, \
            state='normal').place(x=690, y=100) ###---
        methodStringVal.set('Ambos')
        ttk.Combobox(values=['Fellenius', 'Bishop', 'Ambos'], state='disable',\
            textvariable=methodStringVal, width=7).place(x=420, y=300)
guiwin.py 文件源码 项目:pysaf 作者: cstarcher 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def create_zip_button(self, gs):
        """Expand frame to reveal options when Create ZIP File is selected."""
        if self.zip_button_var.get() == 1:
            self.split_button_var = tk.IntVar()
            self.split_button = ttk.Checkbutton(self.zip_frame,
                                                text='Split ZIP File',
                                                variable=self.split_button_var)
            self.split_button.grid(row=2, column=0, sticky='w')
            self.split_button.grid_configure(padx=2, pady=5)
            self.split_entry_var = tk.IntVar()
            self.split_entry = ttk.Entry(self.zip_frame,
                                         width=3,
                                         justify='right',
                                         textvariable=self.split_entry_var)
            self.split_entry.grid(row=2, column=1, sticky='e')
            self.split_entry.grid_configure(pady=5)
            self.split_entry_var.set('2')
            self.split_combo = ttk.Combobox(self.zip_frame,
                                            width=4,
                                            justify='left',
                                            values='MB GB')
            self.split_combo.current(1)
            self.split_combo.grid(row=2, column=2, sticky='w')
            self.split_combo.grid_configure(pady=5)
        else:
            self.split_button.destroy()
            self.split_entry.destroy()
            self.split_combo.destroy()
gui.py 文件源码 项目:pysaf 作者: cstarcher 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def create_zip_button(self, gs):
        """Expand frame to reveal options when Create ZIP File is selected."""
        if self.zip_button_var.get() == 1:
            self.split_button_var = tk.IntVar()
            self.split_button = ttk.Checkbutton(self.zip_frame,
                                                text='Split ZIP File',
                                                variable=self.split_button_var)
            self.split_button.grid(row=2, column=0, sticky='w')
            self.split_button.grid_configure(padx=2, pady=5)
            self.split_entry_var = tk.IntVar()
            self.split_entry = ttk.Entry(self.zip_frame,
                                         width=3,
                                         justify='right',
                                         textvariable=self.split_entry_var)
            self.split_entry.grid(row=2, column=1, sticky='e')
            self.split_entry.grid_configure(pady=5)
            self.split_entry_var.set('2')
            self.split_combo = ttk.Combobox(self.zip_frame,
                                            width=4,
                                            justify='left',
                                            values='MB GB')
            self.split_combo.current(1)
            self.split_combo.grid(row=2, column=2, sticky='w')
            self.split_combo.grid_configure(pady=5)
        else:
            self.split_button.destroy()
            self.split_entry.destroy()
            self.split_combo.destroy()
gui.py 文件源码 项目:qcri 作者: douville 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _create_local_pane(self, full_pane):
        local_pane = tk.LabelFrame(full_pane, text='Test Results')

        self.choose_results_button = tk.Button(
            local_pane,
            text='Results',
            width=15,
            command=self._load_run_results)
        self.choose_results_button.grid(
            row=0, column=0, sticky='ew', padx=10, pady=5)
        self.choose_results_entry = tk.Entry(
            local_pane, state='disabled', textvariable=self.runresultsvar)
        self.choose_results_entry.grid(
            row=0, column=1, sticky='nsew', padx=10, pady=5)
        self.choose_parser = ttk.Combobox(
            local_pane, show='', state='disabled')
        self.choose_parser.bind(
            '<<ComboboxSelected>>', self._on_parser_changed)
        self.choose_parser.grid(
            row=1, column=0, columnspan=2, sticky='nsew', padx=10, pady=7)
        self.runresultsview = TestResultsView(
            local_pane, on_selected=self._on_test_result_selected)
        self.runresultsview.grid(
            row=2, column=0, columnspan=2, sticky='nsew', padx=10, pady=5)
        self.runresultsview.rowconfigure(0, weight=1)
        self.runresultsview.columnconfigure(0, weight=1)

        local_pane.rowconfigure(2, weight=1)
        local_pane.columnconfigure(1, weight=1)
        local_pane.config(padx=10)
        return local_pane
gui.py 文件源码 项目:qcri 作者: douville 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _make_combo(self, frame, text):
        tk.Label(frame, text='{}:'.format(text)).pack(side=tk.TOP)
        cbo = ttk.Combobox(frame, width=16, show='')
        cbo.pack(side=tk.TOP, padx=10, fill=tk.BOTH)
        cbo.bind('<Return>', self.check_password)
        cbo['values'] = self.history.get(text.lower(), [])
        if cbo['values']:
            cbo.set(cbo['values'][-1])
        return cbo
GUI_MySQL.py 文件源码 项目:Python-GUI-Programming-Cookbook-Second-Edition 作者: PacktPublishing 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def defaultFileEntries(self): 
        self.fileEntry.delete(0, tk.END)
        self.fileEntry.insert(0, 'Z:\\')        # bogus path
        self.fileEntry.config(state='readonly')         

        self.netwEntry.delete(0, tk.END)
        self.netwEntry.insert(0, 'Z:\\Backup')  # bogus path                      

    # Combobox callback
GUI_Not_OOP.py 文件源码 项目:Python-GUI-Programming-Cookbook-Second-Edition 作者: PacktPublishing 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def createWidgets():    
    tabControl = ttk.Notebook(win)     
    tab1 = ttk.Frame(tabControl)            
    tabControl.add(tab1, text='Tab 1')    
    tabControl.pack(expand=1, fill="both")  
    monty = ttk.LabelFrame(tab1, text=' Mighty Python ')
    monty.grid(column=0, row=0, padx=8, pady=4)        

    ttk.Label(monty, text="Enter a name:").grid(column=0, row=0, sticky='W')
    name = tk.StringVar()
    nameEntered = ttk.Entry(monty, width=12, textvariable=name)
    nameEntered.grid(column=0, row=1, sticky='W')

    action = ttk.Button(monty, text="Click Me!")   
    action.grid(column=2, row=1)

    ttk.Label(monty, text="Choose a number:").grid(column=1, row=0)
    number = tk.StringVar()
    numberChosen = ttk.Combobox(monty, width=12, textvariable=number)
    numberChosen['values'] = (42)
    numberChosen.grid(column=1, row=1)
    numberChosen.current(0)

    scrolW = 30; scrolH = 3
    scr = scrolledtext.ScrolledText(monty, width=scrolW, height=scrolH, wrap=tk.WORD)
    scr.grid(column=0, row=3, sticky='WE', columnspan=3)

    menuBar = Menu(tab1)
    win.config(menu=menuBar)
    fileMenu = Menu(menuBar, tearoff=0)
    menuBar.add_cascade(label="File", menu=fileMenu)
    helpMenu = Menu(menuBar, tearoff=0)
    menuBar.add_cascade(label="Help", menu=helpMenu)

    nameEntered.focus()     
#======================
GUI_Complexity_end_tab3_multiple_notebooks.py 文件源码 项目:Python-GUI-Programming-Cookbook-Second-Edition 作者: PacktPublishing 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def display_tab1():
    # Container frame to hold all other widgets
    monty = ttk.LabelFrame(display_area, text=' Mighty Python ')
    monty.grid(column=0, row=0, padx=8, pady=4)

    # Adding a Label
    ttk.Label(monty, text="Enter a name:").grid(column=0, row=0, sticky='W')

    # Adding a Textbox Entry widget
    name = tk.StringVar()
    nameEntered = ttk.Entry(monty, width=12, textvariable=name)
    nameEntered.grid(column=0, row=1, sticky='W')

    ttk.Label(monty, text="Choose a number:").grid(column=1, row=0)
    number = tk.StringVar()
    numberChosen = ttk.Combobox(monty, width=12, textvariable=number)
    numberChosen['values'] = (1, 2, 4, 42, 100)
    numberChosen.grid(column=1, row=1)
    numberChosen.current(0)

    # Adding a Button
    action = ttk.Button(monty, text="Click Me!", command= lambda: clickMe(action, name, number))   
    action.grid(column=2, row=1)

    # Using a scrolled Text control    
    scrolW  = 30; scrolH  =  3
    scr = scrolledtext.ScrolledText(monty, width=scrolW, height=scrolH, wrap=tk.WORD)
    scr.grid(column=0, row=3, sticky='WE', columnspan=3)  

    # Adding a Spinbox widget using a set of values
    spin = Spinbox(monty, values=(1, 2, 4, 42, 100), width=5, bd=8, command= lambda: _spin(spin, scr)) 
    spin.grid(column=0, row=2, sticky='W')  

    # Adding another Button
    clear = ttk.Button(monty, text="Clear Text", command= lambda: clearScrol(scr))   
    clear.grid(column=2, row=2)

    # Adding more Feature Buttons
    startRow = 4
    for idx in range(12):
        if idx < 2:
            colIdx = idx
            col = colIdx
        else:
            col += 1
        if not idx % 3: 
            startRow += 1
            col = 0

        b = ttk.Button(monty, text="Feature " + str(idx+1))   
        b.grid(column=col, row=startRow)   

#------------------------------------------
GUI_OOP.py 文件源码 项目:Python-GUI-Programming-Cookbook-Second-Edition 作者: PacktPublishing 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def createWidgets(self):    
        tabControl = ttk.Notebook(self.win)     
        tab1 = ttk.Frame(tabControl)            
        tabControl.add(tab1, text='Tab 1')    
        tabControl.pack(expand=1, fill="both")  
        self.monty = ttk.LabelFrame(tab1, text=' Mighty Python ')
        self.monty.grid(column=0, row=0, padx=8, pady=4)        

        ttk.Label(self.monty, text="Enter a name:").grid(column=0, row=0, sticky='W')
        self.name = tk.StringVar()
        nameEntered = ttk.Entry(self.monty, width=12, textvariable=self.name)
        nameEntered.grid(column=0, row=1, sticky='W')

        self.action = ttk.Button(self.monty, text="Click Me!")   
        self.action.grid(column=2, row=1)

        ttk.Label(self.monty, text="Choose a number:").grid(column=1, row=0)
        number = tk.StringVar()
        numberChosen = ttk.Combobox(self.monty, width=12, textvariable=number)
        numberChosen['values'] = (42)
        numberChosen.grid(column=1, row=1)
        numberChosen.current(0)

        scrolW = 30; scrolH = 3
        self.scr = scrolledtext.ScrolledText(self.monty, width=scrolW, height=scrolH, wrap=tk.WORD)
        self.scr.grid(column=0, row=3, sticky='WE', columnspan=3)

        menuBar = Menu(tab1)
        self.win.config(menu=menuBar)
        fileMenu = Menu(menuBar, tearoff=0)
        menuBar.add_cascade(label="File", menu=fileMenu)
        helpMenu = Menu(menuBar, tearoff=0)
        menuBar.add_cascade(label="Help", menu=helpMenu)

        nameEntered.focus()     
#==========================
test_widgets.py 文件源码 项目:Craft-Clash 作者: Derpyface-Development-Co 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_values(self):
        def check_get_current(getval, currval):
            self.assertEqual(self.combo.get(), getval)
            self.assertEqual(self.combo.current(), currval)

        self.assertEqual(self.combo['values'],
                         () if tcl_version < (8, 5) else '')
        check_get_current('', -1)

        self.checkParam(self.combo, 'values', 'mon tue wed thur',
                        expected=('mon', 'tue', 'wed', 'thur'))
        self.checkParam(self.combo, 'values', ('mon', 'tue', 'wed', 'thur'))
        self.checkParam(self.combo, 'values', (42, 3.14, '', 'any string'))
        self.checkParam(self.combo, 'values', '',
                        expected='' if get_tk_patchlevel() < (8, 5, 10) else ())

        self.combo['values'] = ['a', 1, 'c']

        self.combo.set('c')
        check_get_current('c', 2)

        self.combo.current(0)
        check_get_current('a', 0)

        self.combo.set('d')
        check_get_current('d', -1)

        # testing values with empty string
        self.combo.set('')
        self.combo['values'] = (1, 2, '', 3)
        check_get_current('', 2)

        # testing values with empty string set through configure
        self.combo.configure(values=[1, '', 2])
        self.assertEqual(self.combo['values'],
                         ('1', '', '2') if self.wantobjects else
                         '1 {} 2')

        # testing values with spaces
        self.combo['values'] = ['a b', 'a\tb', 'a\nb']
        self.assertEqual(self.combo['values'],
                         ('a b', 'a\tb', 'a\nb') if self.wantobjects else
                         '{a b} {a\tb} {a\nb}')

        # testing values with special characters
        self.combo['values'] = [r'a\tb', '"a"', '} {']
        self.assertEqual(self.combo['values'],
                         (r'a\tb', '"a"', '} {') if self.wantobjects else
                         r'a\\tb {"a"} \}\ \{')

        # out of range
        self.assertRaises(tkinter.TclError, self.combo.current,
            len(self.combo['values']))
        # it expects an integer (or something that can be converted to int)
        self.assertRaises(tkinter.TclError, self.combo.current, '')

        # testing creating combobox with empty string in values
        combo2 = ttk.Combobox(self.root, values=[1, 2, ''])
        self.assertEqual(combo2['values'],
                         ('1', '2', '') if self.wantobjects else '1 2 {}')
        combo2.destroy()
test_widgets.py 文件源码 项目:Craft-Clash 作者: Derpyface-Development-Co 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_values(self):
        def check_get_current(getval, currval):
            self.assertEqual(self.combo.get(), getval)
            self.assertEqual(self.combo.current(), currval)

        self.assertEqual(self.combo['values'],
                         () if tcl_version < (8, 5) else '')
        check_get_current('', -1)

        self.checkParam(self.combo, 'values', 'mon tue wed thur',
                        expected=('mon', 'tue', 'wed', 'thur'))
        self.checkParam(self.combo, 'values', ('mon', 'tue', 'wed', 'thur'))
        self.checkParam(self.combo, 'values', (42, 3.14, '', 'any string'))
        self.checkParam(self.combo, 'values', '',
                        expected='' if get_tk_patchlevel() < (8, 5, 10) else ())

        self.combo['values'] = ['a', 1, 'c']

        self.combo.set('c')
        check_get_current('c', 2)

        self.combo.current(0)
        check_get_current('a', 0)

        self.combo.set('d')
        check_get_current('d', -1)

        # testing values with empty string
        self.combo.set('')
        self.combo['values'] = (1, 2, '', 3)
        check_get_current('', 2)

        # testing values with empty string set through configure
        self.combo.configure(values=[1, '', 2])
        self.assertEqual(self.combo['values'],
                         ('1', '', '2') if self.wantobjects else
                         '1 {} 2')

        # testing values with spaces
        self.combo['values'] = ['a b', 'a\tb', 'a\nb']
        self.assertEqual(self.combo['values'],
                         ('a b', 'a\tb', 'a\nb') if self.wantobjects else
                         '{a b} {a\tb} {a\nb}')

        # testing values with special characters
        self.combo['values'] = [r'a\tb', '"a"', '} {']
        self.assertEqual(self.combo['values'],
                         (r'a\tb', '"a"', '} {') if self.wantobjects else
                         r'a\\tb {"a"} \}\ \{')

        # out of range
        self.assertRaises(tkinter.TclError, self.combo.current,
            len(self.combo['values']))
        # it expects an integer (or something that can be converted to int)
        self.assertRaises(tkinter.TclError, self.combo.current, '')

        # testing creating combobox with empty string in values
        combo2 = ttk.Combobox(self.root, values=[1, 2, ''])
        self.assertEqual(combo2['values'],
                         ('1', '2', '') if self.wantobjects else '1 2 {}')
        combo2.destroy()


问题


面经


文章

微信
公众号

扫码关注公众号