Python tkinter.ttk 模块,Labelframe() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用tkinter.ttk.Labelframe()

项目:serialplot    作者:crxguy52    | 项目源码 | 文件源码
def __init__(self, parent):
        ttk.Frame.__init__(self, parent)
        self.parent = parent
        self['padding'] = '4'

        self.TKvariables = {}

        #Read in the defaults
        for key in defaults:

            if key[0:5] == 'graph' or key.find('ylims') >= 0:
                self.TKvariables.update({key:[]})

                for val in range(len(defaults[key])):
                    self.TKvariables[key].append(tk.StringVar(value=defaults[key][val]))

            else:
                self.TKvariables.update({key:tk.StringVar(value=defaults[key])})      

        num_vars = int(self.TKvariables['datalength'].get())
        self.datalist = list(range(1,num_vars+1))

        #Create a combobox containing the available COM ports        
        comlst = self.get_comlst()
        self.COMbox = ttk.Labelframe(self, text='COM port to source data from')
        self.COMcombo = ttk.Combobox(self.COMbox,  width=60, values=comlst, \
            state='readonly', textvariable=self.TKvariables['COMport'],\
            postcommand=self.updateCOMbox )
        self.COMbox.grid(row = 0, column = 0, columnspan = 5)
        self.COMcombo.grid()

        #Create an "about" text box
        ABOUTframe = ttk.LabelFrame(self, text = 'What it does')
        ABOUTlabel = ttk.Label(ABOUTframe, text= \
            'Graphs data coming in over the serial port in a comma '
            'seperated variable string. Hover over each option to get ' 
            'a description of what the setting does', wraplength = 140)
        ABOUTframe.grid(row=1, column = 0, rowspan = 2, columnspan = 2, \
            sticky = 'nw, se', padx= 3, pady = 5)
        CreateToolTip(ABOUTlabel,\
        "The default values can be changed by opening defaults.py with a text "
        "editor and changing the values")
        ABOUTlabel.pack()        

        #Create a Graph! and About buttons
        GObut = ttk.Button(self, text='Go!', command=self.goButton)
        GObut.grid(row=6, column = 0, sticky = 'we')
        ABOUTbut = ttk.Button(self, text='About', command=self.aboutButton) 
        ABOUTbut.grid(row = 6, column = 1, sticky = 'we')

        #Create an instance of the class for the config panel
        notebook = ConfigNotebook(self, self)

        #Update the state of the graphs based on the defaults and grid
        notebook.updateGraphs()     
        notebook.grid(row=1, column=3, columnspan=2, rowspan=6, sticky = 'nsew', \
                padx = 5, pady = 5)

        #Bind the enter key to start the program
        self.parent.bind("<Return>", lambda event:self.goButton())
项目:pyGISS    作者:afourmy    | 项目源码 | 文件源码
def __init__(self, path_app):
        super().__init__()
        self.title('Extended PyGISS')
        path_icon = abspath(join(path_app, pardir, 'images'))

        # generate the PSF tk images
        img_psf = ImageTk.Image.open(join(
                                          path_icon, 
                                          'node.png'
                                          )
                                    )

        selected_img_psf = ImageTk.Image.open(join(
                                          path_icon, 
                                          'selected_node.png'
                                          )
                                    )
        self.psf_button_image = ImageTk.PhotoImage(img_psf.resize((100, 100)))
        self.node_image = ImageTk.PhotoImage(img_psf.resize((40, 40)))
        self.selected_node_image = ImageTk.PhotoImage(selected_img_psf.resize((40, 40)))

        for widget in (
                       'Button',
                       'Label', 
                       'Labelframe', 
                       'Labelframe.Label', 
                       ):
            ttk.Style().configure('T' + widget, background='#A1DBCD')

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

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

        menu = tk.Menu(self)
        menu.add_command(label="Import shapefile", command=self.map.import_map)
        self.config(menu=menu)

        # if motion is called, the left-click button was released and we 
        # can stop the drag and drop process
        self.bind_all('<Motion>', self.stop_drag_and_drop)
        self.drag_and_drop = False

        self.image = None
        self.bind_all('<B1-Motion>', lambda _:_)
项目:pyGISS    作者:afourmy    | 项目源码 | 文件源码
def __init__(self, controller):            
        super().__init__(controller)
        self.configure(background='#A1DBCD')   

        lf_creation = ttk.Labelframe(
                                     self, 
                                     text = 'Object management', 
                                     padding = (6, 6, 12, 12)
                                     )
        lf_creation.grid(row=0, column=0, padx=5, pady=5)

        psf_object_label = tk.Label(
                               self, 
                               image = controller.psf_button_image, 
                               relief = 'flat', 
                               bg = '#A1DBCD'
                               )
        psf_object_label.bind('<Button-1>', controller.start_drag_and_drop)
        psf_object_label.grid(row=0, column=0, pady=10, padx=55, in_=lf_creation)

        import_nodes_button = ttk.Button(self, text='Import nodes',
                            command=controller.map.import_nodes, width=20)
        import_nodes_button.grid(row=2, column=0, pady=5, in_=lf_creation)

        lf_projection = ttk.Labelframe(
                                       self, 
                                       text = 'Projection management', 
                                       padding = (6, 6, 12, 12)
                                       )
        lf_projection.grid(row=1, column=0, padx=5, pady=5)

        self.projection_list = ttk.Combobox(self, width=18)
        self.projection_list['values'] = tuple(controller.map.projections)
        self.projection_list.current(0)
        self.projection_list.grid(row=0, column=0, in_=lf_projection)

        change_projection_button = ttk.Button(self, text='Change projection',
                            command=controller.map.change_projection, width=20)
        change_projection_button.grid(row=1, column=0, pady=5, in_=lf_projection)

        lf_map_management = ttk.Labelframe(
                                        self, 
                                        text = 'Map management', 
                                        padding = (6, 6, 12, 12)
                                        )
        lf_map_management.grid(row=2, column=0, padx=5, pady=5)

        delete_map = ttk.Button(self, text='Delete map',
                            command=controller.map.delete_map, width=20)
        delete_map.grid(row=0, column=0, pady=5, in_=lf_map_management)

        delete_selection = ttk.Button(self, text='Delete selected nodes',
                            command=controller.map.delete_selected_nodes, width=20)
        delete_selection.grid(row=1, column=0, pady=5, in_=lf_map_management)