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


Python OptionMenu.pack方法代码示例

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


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

示例1: Example

# 需要导入模块: from tkinter import OptionMenu [as 别名]
# 或者: from tkinter.OptionMenu import pack [as 别名]
class Example(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)

        self.dict = {'Asia': ['Japan', 'China', 'India'],
                     'Europe': ['Portugal', 'Switzerland', 'Ukraine']}

        self.var_a = StringVar(self)
        self.var_b = StringVar(self)

        self.var_a.trace('w', self.update_options)

        self.option_menu_a = OptionMenu(self, self.var_a, *self.dict.keys())
        self.option_menu_a.pack(side="top")
        self.option_menu_a["width"] = 10
        self.option_menu_b = OptionMenu(self, self.var_b, '')
        self.option_menu_b["width"] = 10
        self.option_menu_b.pack(side="top")

        self.var_a.set('Asia')

    def update_options(self, *args):
        countries = self.dict[self.var_a.get()]
        self.var_b.set(countries[0])

        menu = self.option_menu_b['menu']
        menu.delete(0, 'end')

        for c in countries:
            menu.add_command(label=c, command=lambda x=c: self.var_b.set(x))
开发者ID:dossan,项目名称:tkinter,代码行数:32,代码来源:sync_two_option_menus.py

示例2: GuiGeneratorSelect

# 需要导入模块: from tkinter import OptionMenu [as 别名]
# 或者: from tkinter.OptionMenu import pack [as 别名]
class GuiGeneratorSelect(Frame):
    def __init__(self, parent, generators):
        Frame.__init__(self, parent)
        self.parent = parent
        self.pack()
        
        self._generators = generators
        self._generatorName = StringVar()
        self._generatorName.set(generators[0].getName())
        self._generatorName.trace("w", self._switchSettings)
        
        self._generatorLbl = Label(self, text="Generator");
        self._generatorLbl.pack(side=LEFT)
        
        param = (self, self._generatorName) + tuple(i.getName() for i in generators)
        self._generatorOpt = OptionMenu(*param)
        self._generatorOpt.pack(side=LEFT)
        
        
        self._switchSettings()
        
    def _switchSettings(self, *args):
       print("DBG: switch generator settings")
       for i in self._generators:
           if i.getName() == self._generatorName.get(): 
               i.pack()
               self._generatorGui = i
               print("pack " + str(i.getName()))
           else:
               i.pack_forget() 
               print("unpack " + str(i.getName()))
    
    def getCurrGeneratorGui(self):
        return self._generatorGui         
开发者ID:awaken1988,项目名称:pyTools,代码行数:36,代码来源:tas_bytegenerator.py

示例3: _init_corpus_select

# 需要导入模块: from tkinter import OptionMenu [as 别名]
# 或者: from tkinter.OptionMenu import pack [as 别名]
    def _init_corpus_select(self, parent):
        innerframe = Frame(parent, background=self._BACKGROUND_COLOUR)
        self.var = StringVar(innerframe)
        self.var.set(self.model.DEFAULT_CORPUS)
        Label(innerframe, justify=LEFT, text=' Corpus: ', background=self._BACKGROUND_COLOUR, padx = 2, pady = 1, border = 0).pack(side='left')

        other_corpora = list(self.model.CORPORA.keys()).remove(self.model.DEFAULT_CORPUS)
        om = OptionMenu(innerframe, self.var, self.model.DEFAULT_CORPUS, command=self.corpus_selected, *self.model.non_default_corpora())
        om['borderwidth'] = 0
        om['highlightthickness'] = 1
        om.pack(side='left')
        innerframe.pack(side='top', fill='x', anchor='n')
开发者ID:CaptainAL,项目名称:Spyder,代码行数:14,代码来源:collocations_app.py

示例4: createWidgets

# 需要导入模块: from tkinter import OptionMenu [as 别名]
# 或者: from tkinter.OptionMenu import pack [as 别名]
 def createWidgets(self):
     self.sayHi = tk.Button(self)
     self.sayHi["text"] = "Eds Button"
     self.sayHi["command"] = self.say_Hello
     self.sayHi.pack(side="bottom")
     
     for option in options:
         f = Frame(self)
         f.pack(side="bottom")
         Label(f, text=option).pack(side="left")
         v = StringVar(self)
         o = OptionMenu(f, v, *options.get(option).values())
         o.pack(side="right")
         self.options[option] = v
开发者ID:ekozlowski,项目名称:MinecraftServerGUI,代码行数:16,代码来源:main.py

示例5: Tk

# 需要导入模块: from tkinter import OptionMenu [as 别名]
# 或者: from tkinter.OptionMenu import pack [as 别名]
from tkinter import Tk, StringVar, OptionMenu, Button
import sys

OPTIONS = sys.argv[1].split("|")

root = Tk()

variable = StringVar(root)
variable.set(OPTIONS[0])  # default value

w = OptionMenu(root, variable, *OPTIONS)
w.pack()


def ok():
    sys.stdout.write(variable.get())
    sys.stdout.flush()
    root.destroy()


button = Button(root, text="OK", command=ok)
button.pack()

root.mainloop()
开发者ID:csprance,项目名称:CE_Python,代码行数:26,代码来源:better_combo_box.py

示例6: refreshWidget

# 需要导入模块: from tkinter import OptionMenu [as 别名]
# 或者: from tkinter.OptionMenu import pack [as 别名]
    def refreshWidget(self) :
        #print "refresh"
        self.card_win.pack_forget()
        import unicodedata
        #Card window      
        self.card_win = PanedWindow(self.card_win.master, orient=VERTICAL)
        self.card_win.pack(side=TOP, expand=True, fill=BOTH, pady=2, padx=2)
        
        
        #Create the name zone
        name_zone=PanedWindow(self.card_win, orient=HORIZONTAL)
        name = StringVar() 
        name.set(self.name)
        def modifName(*args) :
            try :
                assert('"' not in name.get())
                name.get().encode('ascii')
            except Exception as e:
                print ("error on name")
                name.set(self.name)
                return
            old = self.name in Card.blocked_creature
            self.name=name.get()
            if old or self.name in Card.blocked_creature :
                self.refreshWidget()
        name.trace("w", modifName)
        name_wid=Entry(name_zone, width=30,textvariable=name)
        name_wid.pack()
        name_zone.add(name_wid)
        #Create the cost ad star stringvar
        #print int(floor(self.getCost()))
        self.cost=StringVar()
        self.stars=StringVar()
        cost_wid=Label(None, textvariable=self.cost, background='red',width=5, anchor=W)
        star_wid=Label(None, textvariable=self.stars, background='blue', anchor=E)
        self.cost.set(str(int(floor(self.getCost()))))
        self.stars.set("*"*self.getStars())
        #Add them in name zone
        name_zone.add(cost_wid)
        name_zone.add(star_wid)
        
        
        #Create an Image Zone
        image_zone=Button(self.card_win,  command=self.choosePhoto)
        if hasattr(self,"photofile") and self.photofile :            
            print ("Image: ",self.photofile)
            try :
                pilImage=Image.open(self.photofile)
                img=PhotoImage(pilImage,master=image_zone)
            except :
               decomp=self.photofile.split('/')
               for i in range(1,6) :
                   try :
                       fname="/".join(decomp[-i:])
                       print ("try to open",fname)
                       pilImage = Image.open(fname)
                       img=PhotoImage(pilImage,master=image_zone)
                       self.photofile=fname
                       break
                   except :
                       self.photofile=None
        if self.photofile :
            w, h = img.width(), img.height()
            print('wh',w,h)
            if h>400 :
                print("reduction")
                img=PhotoImage(pilImage.resize((w//2,h//2), Image.ANTIALIAS),master=image_zone)
            image_zone=Button(self.card_win,image=img,  command=self.choosePhoto)
            image_zone.image=img
            #image_zone.configure(image=image_zone.image,width=50,height=50,compound=RIGHT)
            #image_zone.pack()
            #print "IMAGE CHANGED"
        else :
            from os import path
            fname=self.name.replace(" ","_")
            if path.isfile("Cards/"+fname+".png") :
                image_zone.config(text='image can be taken from\n'+"Cards/"+fname+".png",background='white',anchor=CENTER)
            else :
                image_zone.config(text='clic to choose image',background='white',anchor=CENTER)

        #image_zone.pack()
        
        
        # POWER ZONE
        power_zone=PanedWindow(self.card_win, orient=VERTICAL)
        #fenetre=self.card_win.master
        def removePowerCreator(px) :
            def removePower(*args) :
                #print 'avant',list_pow
                self.bonus.remove(px)
                #print 'apres',list_pow
                #self.card_win.pack_forget()
                self.refreshWidget()
            return removePower
        for p in self.bonus :
            powline =  PanedWindow(self.card_win, orient=HORIZONTAL)
            pow_wid=p.initWidget(powline)
            powline.add(pow_wid)
            removepow=Button(powline, text="X", command=removePowerCreator(p), anchor=E)
            removepow.pack()
#.........这里部分代码省略.........
开发者ID:IreneeMichel,项目名称:MagicCardBattle,代码行数:103,代码来源:Card.py

示例7: Frontend

# 需要导入模块: from tkinter import OptionMenu [as 别名]
# 或者: from tkinter.OptionMenu import pack [as 别名]
class Frontend():
    def __init__(self,x,y,b):
        self.x=str(x)   #1600
        self.y=str(y)   #900
        self.pressed=0
        self.b=10
        self.c=30
        self.grapher=0
        self.graph=[0,0,0,0]
        self.root=b
    def startwindow(self):
       # self.root=Tk()
        a=str(self.x+'x'+self.y)
        self.root.title('Wahrscheinlichkeinten & Simulation')
        self.root.geometry(a)
        self.g=Label(self.root,bg='white')
        self.g.place(x=0,y=0,width=self.x,height=self.y)
       # self.g.bind('<1>',self.optioncanged)
        self.lst1 = ['Marriage','Atom','BubbleGum','House_of_Cards','Lotto','SecretSanta','Coins']
        self.var1 = StringVar(self.root)
        self.var1.set('Marriage')
        self.drop = OptionMenu(self.root,self.var1,*self.lst1)
        self.drop.config(font=('Arial',(30)),bg='white')
        self.drop['menu'].config(font=('calibri',(20)),bg='white')
        self.drop.pack(side=TOP)
        self.photo = PhotoImage(file='z1.gif')
        self.label = Label(image=self.photo,borderwidth=0)
        self.label.image = self.photo
        self.label.bind('<1>',self.MouseOneDown)
        self.label.place(y=0,x=int(self.x)-200)
        self.startbutton=Button(self.root,text='Start',font=('Arial',40),bg='#B4045F',borderwidth=5,command=self.startpressed)       
        self.startbutton.place(x=0,y=int(self.y)-100,width=int(self.y)-200,height=100)
        self.csvbutton=Button(self.root,text='Export CSV',font=('Arial',40),bg='green',borderwidth=5,command=self.csvpressed)     
        self.csvbutton.place(x=int(self.x)/2+50,y=int(self.y)-100,width=int(self.y)-230,height=100)
    def startpressed(self):
            if self.grapher==1:
                for x in range(len(self.graph)):
                    if self.graph[x]!=0:
                        self.graph[x].destroy()
                self.grapher=0
                self.root.update()
            a=self.var1.get()
            if self.pressed==1:
                try:
                    self.b=int(self.changer0.get('1.0','end-1c'))
                except (AttributeError,TclError,ValueError):
                    self.b=10
                try:
                    self.c=self.changer2.get('1.0','end-1c')
                except (AttributeError,TclError,ValueError):
                    self.c=1
            if a=='Marriage':
                self.run0=Marriage(self.b)
                self.run0.DEBUG=False
                self.run0.sim()
            elif a=='Atom':
                self.c=float(self.c)
                self.run1=Atom(self.c,self.b)
                self.run1.DEBUG=False
                self.run1.sim()
            elif a=='BubbleGum':
                self.run2=BubbleGum(self.b)
                self.run2.DEBUG=False
                self.run2.sim()
                self.grapher=1
                self.graph=[0,0]
                g=str(round(self.run2.getrel()[0],4))
                h=str(round(self.run2.getrel()[1],4))
                self.graph[0]=Label(self.root,bg='white',text='Durchschnitt Karten zu viel: '+g,font=('calibri',19))
                self.graph[0].place(x=10,y=450)
                self.graph[1]=Label(self.root,bg='white',text='Durchschnitt dass es passiert: '+h,font=('calibri',19))
                self.graph[1].place(x=10,y=500)
            elif a=='House_of_Cards':
                if self.c=='':
                    self.c=0
                else:
                    self.c=int(self.c)
                self.run3=House_of_Cards(self.b,self.c)
                self.run3.DEBUG=False
                self.run3.sim()
                self.grapher=1
                self.graph=[0]
                self.graph[0]=Label(self.root,bg='white',text=('Durchschnitt: '+str(round(self.run3.getrel(),4))),font=('calibri',19))
                self.graph[0].place(x=10,y=450)
            elif a=='Lotto':
                self.run4=Lotto(self.b)
                self.run4.DEBUG=False
                self.run4.sim()
                x=4
                y=1
                count=0
                self.graph=[0,0,0,0]
                self.grapher=1
                self.graph[0]=Label(self.root,bg='black')
                self.graph[0].place(x=10,width=10+(int(self.x)*0.8),height=1,y=int(self.y)-int(self.y)/4*0.5-350)
                self.graph[1]=Label(self.root,text='50%',bg='white',font=('calibri',10))
                self.graph[1].place(x=60+(int(self.x)*0.8),width=50,height=50,y=int(self.y)-int(self.y)/4*0.5-375)
                self.graph[2]=Label(self.root,bg='black')
                self.graph[2].place(x=10,width=20,height=1,y=int(self.y)-350)
                self.graph[3]=Label(self.root,bg='black')
#.........这里部分代码省略.........
开发者ID:lustigo,项目名称:stochastik_sim,代码行数:103,代码来源:Ubuntu_layout.py

示例8: ConfigurationWindow

# 需要导入模块: from tkinter import OptionMenu [as 别名]
# 或者: from tkinter.OptionMenu import pack [as 别名]
class ConfigurationWindow(Frame):
    """
    Klasa GUI konfiguratora roweru

    w metodzie 'createBike' jest tworzony obiekt roweru
    z wykorzystaniem dekoratorów
    """
    def __init__(self, parent, frames, forks, wheelsets, groups, components):
        """
        inicjalizacja obiektu okna - nieistotne dla idei zdania
        """
        super(ConfigurationWindow, self).__init__(parent)
        self._bike = None
        self.parent = parent
        self.frames = frames
        self.forks = forks
        self.wheelsets = wheelsets
        self.groups = groups
        self.components = components
        self.parent.title("Bicycle configurator")
        self._bike_price = StringVar(self.parent)
        self._bike_weight = StringVar(self.parent)
        self._bike_travel = StringVar(self.parent)
        self.price_label = Label(self.parent, textvariable=self._bike_price)
        self.weight_label = Label(self.parent, textvariable=self._bike_weight)
        self.travel_label = Label(self.parent, textvariable=self._bike_travel)

        self.createInterface()
        self.createBike()

        self.price_label.pack()
        self.weight_label.pack()
        self.travel_label.pack()
        
        self.pack(fill=BOTH, expand=1)
        
    def createInterface(self):
        """
        Tworzenie interfejsu - nieistotne dla idei zadania
        """
        self.frame_choice = StringVar(self.parent)
        self.frame_choice.set(tuple(self.frames.keys())[0])
        self.frame_choice.trace("w", self.createBike)
        self.frame_options = OptionMenu(self.parent,self.frame_choice,
                                        *self.frames.keys())
        Label(self.parent,text="Rama:").pack()
        self.frame_options.pack(fill=BOTH, expand=1)

        self.fork_choice = StringVar(self.parent)
        self.fork_choice.set(tuple(self.forks.keys())[0])
        self.fork_choice.trace("w", self.createBike)
        self.fork_options = OptionMenu(self.parent,self.fork_choice,
                                        *self.forks.keys())
        Label(self.parent,text="Widelec:").pack()
        self.fork_options.pack(fill=BOTH, expand=1)

        self.wheelset_choice = StringVar(self.parent)
        self.wheelset_choice.set(tuple(self.wheelsets.keys())[0])
        self.wheelset_choice.trace("w", self.createBike)
        self.wheelset_options = OptionMenu(self.parent,self.wheelset_choice,
                                        *self.wheelsets.keys())
        Label(self.parent,text="Koła:").pack()
        self.wheelset_options.pack(fill=BOTH, expand=1)

        self.group_choice = StringVar(self.parent)
        self.group_choice.set(tuple(self.groups.keys())[0])
        self.group_choice.trace("w", self.createBike)
        self.group_options = OptionMenu(self.parent,self.group_choice,
                                        *self.groups.keys())
        Label(self.parent,text="Grupa osprzętu:").pack()
        self.group_options.pack(fill=BOTH, expand=1)

        self.components_choice = StringVar(self.parent)
        self.components_choice.set(tuple(self.components.keys())[0])
        self.components_choice.trace("w", self.createBike)
        self.components_options = OptionMenu(self.parent,self.components_choice,
                                        *self.components.keys())
        Label(self.parent,text="Komponenty:").pack()
        self.components_options.pack(fill=BOTH, expand=1)

    def createBike(self, *args):
        """
        Metoda tworząca obiekt roweru na zasadanie dekorowania
        obiektu klasy 'Frame'
        """
        frame = self.frames[self.frame_choice.get()]
        
        fork = self.forks[self.fork_choice.get()]
        fork.decorated = frame
        
        wheelset = self.wheelsets[self.wheelset_choice.get()]
        wheelset.decorated = fork
        
        group = self.groups[self.group_choice.get()]
        group.decorated = wheelset
        
        components = self.components[self.components_choice.get()]
        components.decorated = group
        self._bike = components

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

示例9: Masfir

# 需要导入模块: from tkinter import OptionMenu [as 别名]
# 或者: from tkinter.OptionMenu import pack [as 别名]
class Masfir(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.parent = parent

        self._initUI()

    def _initUI(self):
        """ Initialise the UI """
        self.parent.title("Masfir v0.1")
        self.style = Style()
        self.style.theme_use("default")
        self.pack(fill=BOTH, expand=1)

        self._createMenu()
        self._createUIElements()

    def _createMenu(self):
        """ Create the menu """

        menubar = Menu(self.parent)
        self.parent.config(menu=menubar)

        # File Menu
        mnuFile = Menu(menubar)
        mnuFile.add_command(label="Exit", underline=1, command=self._onMenuFileExit)
        menubar.add_cascade(label="File", underline=0, menu=mnuFile)

        # Help Menu
        mnuHelp = Menu(menubar)
        mnuHelp.add_command(label="About", underline=0, command=self._onMenuHelpAbout)
        menubar.add_cascade(label="Help", underline=0, menu=mnuHelp)

    def _createUIElements(self):
        """ Create the main frame's UI elements """

        # Top frame with the Load Directory controls
        frmLoadDir = Frame(self)
        frmLoadDir.pack(side=TOP, anchor=N, fill=X)

        self.sLoadDirVar = StringVar()
        lblLoadDir = Label(frmLoadDir, text="<Empty Directory>", textvariable=self.sLoadDirVar)
        lblLoadDir.pack(side=LEFT)

        btnLoadDir = Button(frmLoadDir, text="Load Directory", command=self._onBtnLoadDir)
        btnLoadDir.pack(side=RIGHT)

        # Dropdown with list of series (directories) detected
        frmSeriesSelector = Frame(self)
        frmSeriesSelector.pack(side=TOP, anchor=N, fill=X)

        self.sSeriesVar = StringVar()
        self.optSeries = OptionMenu(frmSeriesSelector, self.sSeriesVar, 'one', 'two', 'three', 'Loading', command=self._onBtnSeriesSelected)
        self.optSeries.pack(side=LEFT)

        # The two diff-style listboxes containing original and new episode list names
        frmListBoxes = Frame(self)
        frmListBoxes.pack(fill=BOTH, expand=1)

        self.lstOrgFiles = Listbox(frmListBoxes)
        self.lstOrgFiles.bind("<<ListboxSelect>>", self._onListOrgFiles)
        self.lstOrgFiles.pack(side=LEFT, fill=BOTH, expand=1, anchor=W)

        self.lstNewFiles = Listbox(frmListBoxes)
        self.lstNewFiles.bind("<<ListboxSelect>>", self._onListNewFiles)
        self.lstNewFiles.pack(side=RIGHT, fill=BOTH, expand=1, anchor=E)

        # Bottom buttons
        frmFinal = Frame(self)
        frmFinal.pack(side=BOTTOM, anchor=S, fill=X)

        btnRename = Button(frmFinal, text="Rename", command=self._onBtnRename)
        btnRename.pack(side=LEFT)

        btnExit = Button(frmFinal, text="Exit", command=self._onBtnExit)
        btnExit.pack(side=RIGHT)

    def _onBtnLoadDir(self):
        selectedDirectory = filedialog.askdirectory()

        self.optSeries['menu'].delete(0, END)
        # self.optSeries['menu'].insert('one', 'two', 'three')
        self.sSeriesVar.set('two')

        self.sLoadDirVar.set(selectedDirectory)
        # Populate listbox
        self.lstOrgFiles.delete(0, END)
        for item in os.listdir(selectedDirectory):
            self.lstOrgFiles.insert(END, item)

    def _onBtnExit(self):
        self._exit()

    def _onListOrgFiles(self):
        pass

    def _onListNewFiles(self):
        pass

    def _onBtnSeriesSelected(self):
#.........这里部分代码省略.........
开发者ID:claudemuller,项目名称:masfir,代码行数:103,代码来源:masfir.py


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