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


Python OptionMenu.configure方法代码示例

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


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

示例1: add_unit_frame

# 需要导入模块: from Tkinter import OptionMenu [as 别名]
# 或者: from Tkinter.OptionMenu import configure [as 别名]
    def add_unit_frame(self, parent=None, id=1):
        """!
        Construct the frame which is contains the widgets relating to a single
        data logging unit.
        @param self The pointer for the object
        @param id An identifier for use with the frame.  This identifier can be
        an integer or string and is displayed within the label of the frame
        @param parent The parent frame/object to be used for the new frame.
        @return The data logging unit frame
        """
        #Dictionary to encapsulate information
        data_dict = {}
        data_dict['frame'] = StdLabelFrame(parent, text='Device %s' % id)
        #Create dynamic components
        data_dict['unit'] = StringVar()
        data_dict['unit'].set(UNIT_TYPES[0])
        data_dict['status'] = StringVar()
        data_dict['status'].set(CONNECTION_TYPES[0])
        data_dict['reading'] = StringVar()
        data_dict['reading'].set('%0.2f' % 0)
        #Display components
        #Unit selection
        drop_down = OptionMenu(data_dict['frame'],
                               data_dict['unit'],
                               *UNIT_TYPES)
        drop_down.configure(width=MAX_WIDGET_WIDTH,
                            bg='white',
                            borderwidth=0,
                            highlightbackground='white',
                            highlightcolor='white')
        drop_down.grid(row=0, columnspan=2)

        #Connection Status
        StdLabel(data_dict['frame'],
                 text='Connection Status: ').\
            grid(row=1, column=0)
        data_dict['status_widget'] = StdLabel(data_dict['frame'],
                                              textvariable=data_dict['status'],
                                              fg='red')
        data_dict['status_widget'].grid(row=1, column=1)

        #Measurement
        StdLabel(data_dict['frame'],
                 textvariable=data_dict['reading'],
                 font=tkFont.Font(family='Arial',
                                  size=36),
                 bg='gray').\
            grid(row=2, columnspan=2, pady=20)
        return data_dict
开发者ID:benjohnston24,项目名称:pyLogger,代码行数:51,代码来源:pyLoggerGui.py

示例2: MenuFrame

# 需要导入模块: from Tkinter import OptionMenu [as 别名]
# 或者: from Tkinter.OptionMenu import configure [as 别名]
class MenuFrame(Frame):
    """
    Drop down menu in Mapping windows

    __str__ must be an unique identifier
    """
    def __init__(self,parent,items,callback=None,current=None,*args,**kwargs):
        Frame.__init__(self,parent,*args,**kwargs)
        self.var = StringVar(self)
        self.items = items
        if current in self.items:
            self.var.set(current)
        self.var.trace("w", lambda x,y,z,v=self.var: self.onChoice())
        self.delete = None
        self.choice = None
        self.callback = callback
        self.listeners = []
        self.menu = OptionMenu(self,self.var,*([i.name for i in self.items]+["None"]))
        self.menu.configure(width=10)
        
    def onChoice(self):
        if self.callback:
            candidates = [i for i in self.items if i.name == self.var.get()]
            item = None
            if candidates:
                item = candidates[0]
                self.choice = item
            else:
                self.delete = self.choice
            self.callback(item)
            
    def grid(self,*args,**kwargs):
        Frame.grid(self,*args,**kwargs)
        self.menu.grid()
    
    def get(self):
        return self.choice
    
    def set(self,item):
        if item in self.items:
            self.var.set(item)
开发者ID:crosslinks,项目名称:XlinkAnalyzer,代码行数:43,代码来源:item.py

示例3: Main

# 需要导入模块: from Tkinter import OptionMenu [as 别名]
# 或者: from Tkinter.OptionMenu import configure [as 别名]
class Main():

	def __init__(self, master):

		#La intro se puede apagar al final, cumple solo una funcion vistosa

		#Iniciacion propia de la ventan y sus configuraciones
		self.master=master
		self.master.wm_title(R.AppTitle)
		self.widht=(self.master.winfo_screenwidth() - self.master.winfo_reqwidth()) / 2
		self.height=(self.master.winfo_screenheight() - self.master.winfo_reqheight()) / 2
		self.master.geometry("+{0:.0f}+{1:.0f}".format(self.widht, self.height))
		self.master.deiconify()
		self.master.resizable(False,False)
		self.icon=(R.IconPath)
		self.master.iconbitmap(self.icon)
		self.master.configure(background=R.Bgcolor)

		#Definicion de variables variables que estaran en uso.
		self.btnFlecha=Image.open(R.BtnFlechaImgPath)
		self.btnFlechaimg=ImageTk.PhotoImage(self.btnFlecha)
		self.selectMed = StringVar(self.master)
		self.selectMed.set(R.SelectMed)

		#Las variables que usaran para saber que hacer o que reemplazar
		self.fromLabel = StringVar()
		self.fromLabel.set(R.Select)
		self.toLabel=StringVar()
		self.toLabel.set(R.Select)

		#Los valores de las entradas
		self.fromNumber=StringVar()
		self.toNumber=StringVar()

		#La creacion de las partes del programita.
		self.menuChoices()
		self.convertChoice()
		self.convertButton()

	def menuChoices(self):

		#Menu de seleccion principal sobre los tipos que conversion que hara el programa
		self.MenuChoices = OptionMenu(self.master, self.selectMed, R.LongMain,R.AlmacMain, command=self.choice)
		self.MenuChoices.configure(bg="white",fg="black",activebackground="#eceefb",highlightbackground=R.Bgcolor,
									indicatoron=0,image=self.btnFlechaimg,compound='right')
		self.MenuChoices.grid(row=0,column=0)

	def convertChoice(self):

		#Las partes que integran el primer submenu llamado "DE", labelFrame,menu, entrada.
		self.labelFrameFrom=LabelFrame(self.master,text="De",background=R.Bgcolor)
		self.labelFrameFrom.grid(row=1,column=0,padx=5,pady=3)

		self.menuFrom=OptionMenu(self.labelFrameFrom,self.fromLabel,"",)
		self.menuFrom.configure(bg=R.White,fg=R.Black,activebackground=R.hoverBtnColor,highlightbackground=R.Bgcolor,
								indicatoron=0,image=self.btnFlechaimg, compound='right')
		self.menuFrom.grid(row=0,column=0,padx=3,pady=2,sticky=E)

		self.entryFrom=Entry(self.labelFrameFrom,justify='center',textvariable=self.fromNumber)
		self.entryFrom.grid(row=2,column=0,padx=5,pady=5)

		#Las partes que integran el segundo submenu llamado "Hasta", labelFrame, menu, entrada.

		self.labelFrameTo=LabelFrame(self.master,text="Hacia",background=R.Bgcolor)
		self.labelFrameTo.grid(row=1,column=1,padx=5,pady=3)

		self.menuTo=OptionMenu(self.labelFrameTo,self.toLabel,"",)
		self.menuTo.configure(bg=R.White,fg=R.Black, activebackground=R.hoverBtnColor,highlightbackground=R.Bgcolor,
					indicatoron=0,image=self.btnFlechaimg, compound='right')
		self.menuTo.grid(row=0,column=0, padx=3, pady=2, sticky=E)

		self.entryTo=Entry(self.labelFrameTo,justify='center',textvariable=self.toNumber,state="readonly")
		self.entryTo.configure(bg="red", readonlybackground=R.Bgcolor)
		self.entryTo.grid(row=2,column=0,padx=3,pady=5)

	def convertButton(self):
		#El boton Convertir que activa las funcionalidades de los campos
		self.butonimgpath = Image.open(R.BtnConvertirImgPath)
		self.butonTkImage = ImageTk.PhotoImage(self.butonimgpath)
		self.button = Button(self.master,text='Convertir',command=self.choiceFromTo)
		self.button.configure(image=self.butonTkImage, bd=False, highlightthickness=0, activebackground="black")
		self.button.grid(row=3,column=1,sticky=E)

	def choice(self, choices):
		#Al tocar el boton [<- Selecione] se cambia la opcion de medida y se genera opciones acorde
		# error.set("")
		#Opciones acorde en el caso de elegir "Longitudes"
		if choices==R.LongMain:
				self.fromLabel.set(R.LongStart)
				self.toLabel.set(R.LongStart)
				self.clean()
				# medidas= ("kms", "milla","metro","legua","yarda","pie")
				for m in R.LongList:
						self.menuFrom['menu'].add_command(label=m,command=lambda v=self.fromLabel,l=m:v.set(l))
				for m in R.LongList:
						self.menuTo['menu'].add_command(label=m,command=lambda v=self.toLabel,l=m:v.set(l))

		#Genera las opciones si se elige "Almacenamientos"
		elif choices==R.AlmacMain:
				self.fromLabel.set(R.AlmacStart)
#.........这里部分代码省略.........
开发者ID:riojano0,项目名称:Python_Scripts,代码行数:103,代码来源:main.py

示例4: initUIElements

# 需要导入模块: from Tkinter import OptionMenu [as 别名]
# 或者: from Tkinter.OptionMenu import configure [as 别名]
    def initUIElements(self):
        _onEdit = lambda i,j,k: self.onEdit()
        _onType = lambda i,j,k: self.onType()

        for k,v in self.fields.items():
            _data = self.fields[k][0]
            _UIClass = self.fields[k][1]
            _context = self.fields[k][2]
            _toString = lambda x: x
            methods = [m for m in dir(self.data) \
                       if m.lower() == k.lower()+"tostring"]

            if methods:
                _toString = self.data.__getattribute__(methods[0])

            if _UIClass == Entry:
                _var = StringVar(self.parent)
                _var.set(_toString(_data))
                _var.trace("w",_onEdit)
                _label = Label(self,text=self.parseName(k)+":")
                _entry = Entry(self,textvariable=_var)
                _entry.config(width=10)
                self.fields[k] = (_data,_entry,_label,_var)

            elif _UIClass == ColorOption:
                self.fields[k] = (_data,_UIClass,None,None)

            elif _UIClass == OptionMenu and not self.differs:
                _var = StringVar(self.parent)
                _names = [c.name for c in _context]
                _var.set(_data.name)
                _var.trace("w",_onEdit)
                _label = Label(self,text=self.parseName(k)+":")
                _menu = OptionMenu(self,_var,*_names)
                _menu.configure(width=5)
                self.fields[k] = (_data,_menu,_label,_var)

            elif _UIClass == OptionMenu and self.differs:
                if k == "Type":
                    _var = StringVar(self.parent)
                    _names = _data
                    _var.set(_names[0])
                    _var.trace("w",_onType)
                    _label = Label(self,text=self.parseName(k)+":")
                    _menu = OptionMenu(self,_var,*_names)
                    _menu.configure(width=5)
                    self.fields[k] = (_data,_menu,_label,_var)
                elif k == "Choose":
                    _var = StringVar(self.parent)
                    _names = [dI.name for dI in _data.values()[0]]
                    if not _names:
                        _names.append("")
                    _var.set(_names[0])
                    _label = Label(self,text=self.parseName(k)+":")
                    _menu = OptionMenu(self,_var,*_names)
                    _menu.configure(width=5)
                    self.fields[k] = (_data,_menu,_label,_var)

            elif _UIClass == FileFrame:
                _menu = FileFrame(self,self.active,_data)
                self.fields[k] = (_data,_menu,None,None)

            elif _UIClass == MapFrame and not self.active:
                _mapping = _data
                _mapFrame = MapFrame(self,_data,True,self.data)
                self.fields[k] = (_data,_mapFrame,None,None)

            elif _UIClass == ItemList and not self.active:
                _itemList = ItemList(self,_data,_context,True)
                self.fields[k] = (_data,_itemList,None,None)

        if not self.active:
            if is_mac():
                self.apply = ttk.Button(self,text=unichr(10004),command=self.onApply, width=1)
            else:
                self.apply = Button(self,text=unichr(10004),command=self.onApply)
            self.createToolTip(self.apply,"Apply")
            self.delete = Button(self,text="x",command=self.onDelete)
            self.createToolTip(self.delete,"Delete")

        else:
            self.add = Button(self,text="Add",command=self.onAdd)
            self.createToolTip(self.add,"Add "+self.data.__class__.__name__)
            if self.multiple and not self.differs:
                _data = self.data
                self.typeDict = {}
                for dI in _data.values():
                    if "type" in dir(dI):
                        _type = dI.type
                    else:
                        _type = dI.__class__.__name__
                    self.typeDict[_type] = dI.__class__.__name__
                _var = StringVar(self.parent)
                _var.set(self.typeDict.keys()[0])
                _var.trace("w",_onType)
                _label = Label(self,text="Type: ")
                _menu = OptionMenu(self,_var,*self.typeDict.keys())
                _menu.configure(width=12)
                self.fields["type"] = (_data,_menu,_label,_var)
            elif self.multiple and self.differs:
#.........这里部分代码省略.........
开发者ID:crosslinks,项目名称:XlinkAnalyzer,代码行数:103,代码来源:item.py

示例5: update_list

# 需要导入模块: from Tkinter import OptionMenu [as 别名]
# 或者: from Tkinter.OptionMenu import configure [as 别名]
 def update_list(self):
     """Refreshes the list of lists"""
     list_menu = OptionMenu(self, self.list_menu_var,
                            *self.parent.list_list, command=self.update)
     list_menu.configure(width=30)
     self.start_canvas.itemconfig(self.menu, window=list_menu)
开发者ID:Soulreaverm,项目名称:SE206Project,代码行数:8,代码来源:StartFrame.py


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