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


Python Button.image方法代码示例

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


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

示例1: create_toolbar

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import image [as 别名]
    def create_toolbar(self):
        """Creates toolbar, hopefully floating dockable but not yet"""
        self.toolbar = Frame(self.master, bd=1, relief=RAISED)

        self.img = Image.open("exit.png")
        eimg = ImageTk.PhotoImage(self.img)  

        exitButton = Button(self.toolbar, image=eimg, bd=1,
                            relief=RAISED, command=self.control.cmd_exit)
        exitButton.image = eimg
        exitButton.pack(side=TOP, padx=2, pady=2)

        anotherButton = Button(self.toolbar, image=eimg, bd=1,
                               relief=RAISED, command=self.control.cmd_null)
        anotherButton.image = eimg
        anotherButton.pack(side=TOP, padx=2, pady=2)

        anotherButton = Button(self.toolbar, image=eimg, bd=1,
                               relief=RAISED, command=self.control.cmd_null)
        anotherButton.image = eimg
        anotherButton.pack(side=TOP, padx=2, pady=2)

        self.toolbar.pack(side=LEFT, fill=Y)
开发者ID:Patch67,项目名称:Graphics,代码行数:25,代码来源:View.py

示例2: initUI

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import image [as 别名]
    def initUI(self):
      
        self.master.title("Toolbar")
        
        menubar = Menu(self.master)
        self.fileMenu = Menu(self.master, tearoff=0)
        self.fileMenu.add_command(label="Exit", command=self.onExit)
        menubar.add_cascade(label="File", menu=self.fileMenu)
        
        toolbar = Frame(self.master, bd=1, relief=RAISED)

        self.img = Image.open("images.png")
        eimg = ImageTk.PhotoImage(self.img)  

        exitButton = Button(toolbar, image=eimg, relief=FLAT,
            command=self.quit)
        exitButton.image = eimg
        exitButton.pack(side=LEFT, padx=2, pady=2)
       
        toolbar.pack(side=TOP, fill=X)
        self.master.config(menu=menubar)
        self.pack()
开发者ID:rinkeigun,项目名称:linux_module,代码行数:24,代码来源:tktoolbar.py

示例3: refreshWidget

# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import image [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


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