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


Python Label.destroy方法代码示例

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


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

示例1: __init__

# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import destroy [as 别名]
class Menu:
    def __init__(self, master):
        self.master = master
        master.title("TicTacToe")
        self.label_index = 0
        self.label_text = StringVar()
        self.label_text.set('TicTacToe')
        self.lable = Label(master, textvariable=self.label_text)
        self.lable.pack()
        self.start_button = Button(master, text='Start', command=self.start)
        self.start_button.pack()

    def start(self):
        self.lable.destroy()
        self.start_button.destroy()
        self.play()

    def play(self):
        Play(self.master)
开发者ID:slavaromanov,项目名称:TTT,代码行数:21,代码来源:TTT_Tk.py

示例2: __init__

# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import destroy [as 别名]

#.........这里部分代码省略.........
            box = self.widget.bbox("%d.0" % curline)
        if not box:
            box = list(self.widget.bbox("insert"))
            # align to left of window
            box[0] = 0
            box[2] = 0
        x = box[0] + self.widget.winfo_rootx() + 2
        y = box[1] + box[3] + self.widget.winfo_rooty()
        self.tipwindow.wm_geometry("+%d+%d" % (x, y))

    def showtip(self, text, parenleft, parenright):
        """Show the calltip, bind events which will close it and reposition it.
        """
        # Only called in CallTips, where lines are truncated
        self.text = text
        if self.tipwindow or not self.text:
            return

        self.widget.mark_set(MARK_RIGHT, parenright)
        self.parenline, self.parencol = map(int, self.widget.index(parenleft).split("."))

        self.tipwindow = tw = Toplevel(self.widget)
        self.position_window()
        # remove border on calltip window
        tw.wm_overrideredirect(1)
        try:
            # This command is only needed and available on Tk >= 8.4.0 for OSX
            # Without it, call tips intrude on the typing process by grabbing
            # the focus.
            tw.tk.call("::tk::unsupported::MacWindowStyle", "style", tw._w, "help", "noActivates")
        except TclError:
            pass
        self.label = Label(
            tw,
            text=self.text,
            justify=LEFT,
            background="#ffffe0",
            relief=SOLID,
            borderwidth=1,
            font=self.widget["font"],
        )
        self.label.pack()
        tw.lift()  # work around bug in Tk 8.5.18+ (issue #24570)

        self.checkhideid = self.widget.bind(CHECKHIDE_VIRTUAL_EVENT_NAME, self.checkhide_event)
        for seq in CHECKHIDE_SEQUENCES:
            self.widget.event_add(CHECKHIDE_VIRTUAL_EVENT_NAME, seq)
        self.widget.after(CHECKHIDE_TIME, self.checkhide_event)
        self.hideid = self.widget.bind(HIDE_VIRTUAL_EVENT_NAME, self.hide_event)
        for seq in HIDE_SEQUENCES:
            self.widget.event_add(HIDE_VIRTUAL_EVENT_NAME, seq)

    def checkhide_event(self, event=None):
        if not self.tipwindow:
            # If the event was triggered by the same event that unbinded
            # this function, the function will be called nevertheless,
            # so do nothing in this case.
            return
        curline, curcol = map(int, self.widget.index("insert").split("."))
        if (
            curline < self.parenline
            or (curline == self.parenline and curcol <= self.parencol)
            or self.widget.compare("insert", ">", MARK_RIGHT)
        ):
            self.hidetip()
        else:
            self.position_window()
            if self.checkhide_after_id is not None:
                self.widget.after_cancel(self.checkhide_after_id)
            self.checkhide_after_id = self.widget.after(CHECKHIDE_TIME, self.checkhide_event)

    def hide_event(self, event):
        if not self.tipwindow:
            # See the explanation in checkhide_event.
            return
        self.hidetip()

    def hidetip(self):
        if not self.tipwindow:
            return

        for seq in CHECKHIDE_SEQUENCES:
            self.widget.event_delete(CHECKHIDE_VIRTUAL_EVENT_NAME, seq)
        self.widget.unbind(CHECKHIDE_VIRTUAL_EVENT_NAME, self.checkhideid)
        self.checkhideid = None
        for seq in HIDE_SEQUENCES:
            self.widget.event_delete(HIDE_VIRTUAL_EVENT_NAME, seq)
        self.widget.unbind(HIDE_VIRTUAL_EVENT_NAME, self.hideid)
        self.hideid = None

        self.label.destroy()
        self.label = None
        self.tipwindow.destroy()
        self.tipwindow = None

        self.widget.mark_unset(MARK_RIGHT)
        self.parenline = self.parencol = self.lastline = None

    def is_active(self):
        return bool(self.tipwindow)
开发者ID:francois-wellenreiter,项目名称:cpython,代码行数:104,代码来源:calltip_w.py

示例3: Example

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

        
    def initUI(self):
      
        self.parent.title("EGUANA")
        self.style = ttk.Style()        
        self.style.theme_use("alt")        
        
        self.photoName = "eguana.gif"
        self.frame = Frame(self, relief=FLAT, borderwidth=10,bg='#FADC46')

        self.frame.pack(fill=BOTH, expand=True)        
        self.pack(fill=BOTH, expand=True)
        
        self.setupMenuBar()
        self.setupTopBar()  
        
    def setupMenuBar(self):
        
        self.menubar = EguanaMenu(self.parent,self)
        self.parent.config(menu=self.menubar)

    def setupTopBar(self):
        
        self.openButton3D = Button(self.frame,text="Select Directory for 3D EMA",relief=RAISED,command=self.askDirectory)
        self.openButton3D.grid(row=0,column=0, sticky=N+S+E+W,padx=2,pady =2)
        
        self.openButton2D = Button(self.frame,text="Select Directory for 2D EMA",relief=RAISED,command=self.askDirectory);
        self.openButton2D.grid(row=2,column=2, sticky=N+S+E+W,padx=2,pady =2)

        self.p1Button = Button(self.frame,text="Placeholder",relief=RAISED)
        self.p1Button.grid(row=0,column=1, sticky=N+S+E+W,padx=2,pady =2)
        self.p2Button = Button(self.frame,text="Placeholder",relief=RAISED)
        self.p2Button.grid(row=0,column=2, sticky=N+S+E+W,padx=2,pady =2)
        self.p3Button = Button(self.frame,text="Placeholder",relief=RAISED)
        self.p3Button.grid(row=1,column=0, sticky=N+S+E+W,padx=2,pady =2)
        self.p4Button = Button(self.frame,text="Placeholder",relief=RAISED)
        self.p4Button.grid(row=1,column=2, sticky=N+S+E+W,padx=2,pady =2)
        self.p5Button = Button(self.frame,text="Placeholder",relief=RAISED)
        self.p5Button.grid(row=2,column=0, sticky=N+S+E+W,padx=2,pady =2)
        self.p6Button = Button(self.frame,text="Placeholder",relief=RAISED)
        self.p6Button.grid(row=2,column=1, sticky=N+S+E+W,padx=2,pady =2)

        self.openButton3D.bind('<Motion>',self.cursorPosition)
        self.openButton2D.bind('<Motion>',self.cursorPosition)

        self.photo = PhotoImage(file="eguana.gif")
        self.photo = self.photo.subsample(2);
        self.photo_label = Label(self.frame,image=self.photo,borderwidth=0,highlightthickness=0)
        self.photo_label.configure(bg='#FADC46')
        
        self.photo_label.grid(row=1,column=1, sticky=N+S+E+W,padx=2,pady =2)
        
        self.photo_label.image = self.photo
    
    
        self.frame.columnconfigure(0, weight=1)
        self.frame.columnconfigure(1, weight=1)
        self.frame.columnconfigure(2, weight=1)
        self.frame.rowconfigure(0, weight=1)
        self.frame.rowconfigure(1, weight=1)
        self.frame.rowconfigure(2, weight=1)
        
    def askDirectory(self):

        dirStr = filedialog.askdirectory()
        
        if len(dirStr):
            self.openButton3D.destroy()
            self.openButton2D.destroy()
            self.p1Button.destroy()
            self.p2Button.destroy()
            self.p3Button.destroy()
            self.p4Button.destroy()
            self.p5Button.destroy()
            self.p6Button.destroy()

            self.menubar.entryconfigure('Filter', state = 'active')
            self.photo_label.destroy()

            dirStr = 'Input Path : '+dirStr
            
            
            self.frame.grid_forget()
            
           

            self.infoFrame = Frame(self.frame, relief=FLAT, bg='#FADC46')
            self.infoFrame.grid(row=0,column=0,columnspan=3, sticky=N+S+E+W,padx=2,pady =2)
               
        
            self.directoryLabel = Label(self.infoFrame, text="No project currently selected",relief=FLAT)
            self.directoryLabel.grid(row=0,column=0,columnspan=2, sticky=N+S+E+W,padx=2,pady =2)
#.........这里部分代码省略.........
开发者ID:VrishtiDutta,项目名称:EGUANA_Python,代码行数:103,代码来源:EGUANA.py

示例4: CalltipWindow

# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import destroy [as 别名]

#.........这里部分代码省略.........
            return

        self.anchor_widget.mark_set(MARK_RIGHT, parenright)
        self.parenline, self.parencol = map(
            int, self.anchor_widget.index(parenleft).split("."))

        super(CalltipWindow, self).showtip()

        self._bind_events()

    def showcontents(self):
        """Create the call-tip widget."""
        self.label = Label(self.tipwindow, text=self.text, justify=LEFT,
                           background="#ffffd0", foreground="black",
                           relief=SOLID, borderwidth=1,
                           font=self.anchor_widget['font'])
        self.label.pack()

    def checkhide_event(self, event=None):
        """Handle CHECK_HIDE_EVENT: call hidetip or reschedule."""
        if not self.tipwindow:
            # If the event was triggered by the same event that unbound
            # this function, the function will be called nevertheless,
            # so do nothing in this case.
            return None

        # Hide the call-tip if the insertion cursor moves outside of the
        # parenthesis.
        curline, curcol = map(int, self.anchor_widget.index("insert").split('.'))
        if curline < self.parenline or \
           (curline == self.parenline and curcol <= self.parencol) or \
           self.anchor_widget.compare("insert", ">", MARK_RIGHT):
            self.hidetip()
            return "break"

        # Not hiding the call-tip.

        self.position_window()
        # Re-schedule this function to be called again in a short while.
        if self.checkhide_after_id is not None:
            self.anchor_widget.after_cancel(self.checkhide_after_id)
        self.checkhide_after_id = \
            self.anchor_widget.after(CHECKHIDE_TIME, self.checkhide_event)
        return None

    def hide_event(self, event):
        """Handle HIDE_EVENT by calling hidetip."""
        if not self.tipwindow:
            # See the explanation in checkhide_event.
            return None
        self.hidetip()
        return "break"

    def hidetip(self):
        """Hide the call-tip."""
        if not self.tipwindow:
            return

        try:
            self.label.destroy()
        except TclError:
            pass
        self.label = None

        self.parenline = self.parencol = self.lastline = None
        try:
            self.anchor_widget.mark_unset(MARK_RIGHT)
        except TclError:
            pass

        try:
            self._unbind_events()
        except (TclError, ValueError):
            # ValueError may be raised by MultiCall
            pass

        super(CalltipWindow, self).hidetip()

    def _bind_events(self):
        """Bind event handlers."""
        self.checkhideid = self.anchor_widget.bind(CHECKHIDE_EVENT,
                                                   self.checkhide_event)
        for seq in CHECKHIDE_SEQUENCES:
            self.anchor_widget.event_add(CHECKHIDE_EVENT, seq)
        self.anchor_widget.after(CHECKHIDE_TIME, self.checkhide_event)
        self.hideid = self.anchor_widget.bind(HIDE_EVENT,
                                              self.hide_event)
        for seq in HIDE_SEQUENCES:
            self.anchor_widget.event_add(HIDE_EVENT, seq)

    def _unbind_events(self):
        """Unbind event handlers."""
        for seq in CHECKHIDE_SEQUENCES:
            self.anchor_widget.event_delete(CHECKHIDE_EVENT, seq)
        self.anchor_widget.unbind(CHECKHIDE_EVENT, self.checkhideid)
        self.checkhideid = None
        for seq in HIDE_SEQUENCES:
            self.anchor_widget.event_delete(HIDE_EVENT, seq)
        self.anchor_widget.unbind(HIDE_EVENT, self.hideid)
        self.hideid = None
开发者ID:willingc,项目名称:cpython,代码行数:104,代码来源:calltip_w.py

示例5: EguanaGUI

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

        # if not EguanaInit.eguana_root_dir_exists():
        #     EguanaInit.create_eguana_root_dir()
        
    def initUI(self):
      
        self.parent.title("EGUANA")
        self.style = ttk.Style()        
        self.style.theme_use("alt")        
        
        self.photoName = "eguana.gif"
        self.frame = Frame(self, relief=FLAT, borderwidth=10,bg='#FADC46')

        self.frame.pack(fill=BOTH, expand=True)        
        self.pack(fill=BOTH, expand=True)
        
        self.setupMenuBar()
        self.setupTopBar()  
        
    def setupMenuBar(self):
        
        self.menubar = EguanaMenu(self.parent,self)
        self.parent.config(menu=self.menubar)

    def setupTopBar(self):
        
        self.supportedDevices = []        
        
        for fileName in [name for name in os.listdir('./machineConfig') if os.path.isfile('./machineConfig/' + name) and not name == 'eguanaMachineConfig.py' and  name.endswith('.py')]:
        # try:{
            components = fileName.split('.')
            fileName = components[0]
            className = fileName[0].upper() + fileName[1:]
            try:
                module = __import__("machineConfig."+fileName,fromlist=["machineConfig."])                        
                classVar = getattr(module,className)
            except:
                continue
            self.supportedDevices.append(classVar())
            # except:
            #     pass

        self.selectMachineFrame = Frame(self.frame,relief=FLAT,bg='#FADC46')
        self.selectMachineFrame.pack(fill=BOTH,expand=True)
        self.setupSelectMachineButtons()
        
    def setupSelectMachineButtons(self):

        numDevices = len(self.supportedDevices)
        numColumns = 3
        numRows = math.ceil((numDevices+1)/3)
        
        self.photo = PhotoImage(file="eguana.gif")
        self.photo = self.photo.subsample(2);
        self.photo_label = Label(self.selectMachineFrame,image=self.photo,borderwidth=0,highlightthickness=0)
        self.photo_label.configure(bg='#FADC46')
        self.photo_label.grid(row=int(numRows/2),column=1, sticky=N+S+E+W,padx=2,pady =2)
        self.photo_label.image = self.photo        
        
        index = 0
        for i in range(numRows):
            for j in range(numColumns):
                
                if not(j == 1 and i == int(numRows/2)) and (index < numDevices):
                    device = self.supportedDevices[index]
                    b = Button(self.selectMachineFrame,text=device.name,relief=RAISED, command=lambda device=device :self.machineButtonPressed(device))
                    b.grid(row=i,column=j, sticky=N+S+E+W,padx=2,pady =2)
                    index += 1

            
        for i in range(numRows):
            self.selectMachineFrame.rowconfigure(i,weight=1)
         
        for i in range(numColumns):
            self.selectMachineFrame.columnconfigure(i,weight=1)
            

    def machineButtonPressed(self,inputDevice):

        dirStr = filedialog.askdirectory()
        
        if len(dirStr) and inputDevice.isDirectoryValid(dirStr):

            inputDevice.setDirPath(dirStr)
            EguanaModel().machine = inputDevice

            self.selectMachineFrame.destroy()

            self.menubar.inputSelected()

            self.photo_label.destroy()

            dirStr = 'Input Path : '+dirStr
#.........这里部分代码省略.........
开发者ID:RohanBali,项目名称:EGUANA_Python,代码行数:103,代码来源:EGUANA.py

示例6: Frontend

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

示例7: Nim

# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import destroy [as 别名]
class Nim(Tk):
    def __init__(self):
        Tk.__init__(self)
        self.title("Nim")
        self.kamen = PhotoImage(file = './kamen.ppm')
        self.nacin = BooleanVar() #0 is ai, 1 is human
        self.nacin = 0
        self.zahtevnost = DoubleVar() #0, 1, 2 are (easy, medium hard)
        self.vnos_nacina = Entry(self, textvariable = "način")
        ni = Button(self, text="Nova igra", command=self.nova_igra)
        ni.grid(column = 2, row = 0)
        self.platno = Canvas(self, width=700, height = 500, bg='white')
        self.platno.grid(row= 3, column = 0, columnspan=4)
        self.vrhovi = []
        self.z1 = Radiobutton(self, text = "Skoraj Nepremagljivo!", variable = self.zahtevnost, value=1)
        self.z2 = Radiobutton(self, text = "Srednje zahtevno   ", variable = self.zahtevnost, value=2)
        self.z3 = Radiobutton(self, text = "Za majhne punčke ", variable = self.zahtevnost, value=3)
        self.z1.grid(column = 0, row = 0)
        self.z2.grid(column = 0, row = 1)
        self.z3.grid(column = 0, row = 2)
        self.z1.select()
        self.konec = Label()
        self.mainloop()

        
    def nova_igra(self):
#        print(self.zahtevnost.get())
        if self.vrhovi != []:
            self.unici_kamne()
            self.k1.destroy()
            self.k2.destroy()
            self.k3.destroy()
            self.ligralec.destroy()
#        print(self.vrhovi)
        self.vrhovi = [randint(1, 5), randint(1, 5), randint(1, 5)]
        self.kamni = [[],[],[]]
        self.narisi_kamne(1)
        self.ligralec = Label(self, text='Na vrsti ste vi!', bg='white', font=("Calibri",21))
        self.lracunalnik = Label(self, text='Na vrsti je računalnik', bg='white', font=("Calibri",21))
        self.k1 = Label(self, text="Prvi kupček", bg='white')
        self.k1.place(x = 10, y=220)
        self.k2 = Label(self, text="Drugi kupček", bg='white')
        self.k2.place(x = 10, y=330)
        self.k3 = Label(self, text="Tretji kupček", bg='white')
        self.k3.place(x = 10, y=440)
        self.ligralec.place(x=300, y=130)
        self.konec.destroy()

    def preveri_zmagovalca(self, igralec):
        if max(self.vrhovi)<1:
            self.ligralec.destroy()
            self.lracunalnik.destroy()
            if igralec == 0:
                self.konec = Label(text='Čestitamo, zmagali ste!', bg = 'white', font=("Calibri", 24))
            else:
                self.konec = Label(text = 'Več sreče prihodnjič!', bg = 'white', font=("Calibri",24))
            self.konec.place(x=150, y=250)
            self.k1.destroy()
            self.k2.destroy()
            self.k3.destroy()

    def sestevek(self):
        s = 0
        for i in range(len(self.vrhovi)):
            s = s^self.vrhovi[i]
        return s
    def sestevki(self):
        return [a^self.X < a for a in self.vrhovi]
    def naredi_potezo_AI(self):
        #Ta del kode sem dobil tako, da sem priredil kodo iz wikipedije
        #vir: http://en.wikipedia.org/wiki/Nim
        self.X = self.sestevek()
        S = self.sestevki()
        odstranjenih = 0
        if self.X == 0:
            if max(self.vrhovi) >1:
                print("Can't win")
            for i, vrh in enumerate(self.vrhovi):
                if vrh>0:
                    izbrani, odstranjenih = i, vrh
        else:
            izbrani = S.index(True)
            odstranjenih = self.vrhovi[izbrani] - (self.vrhovi[izbrani]^self.X)
            dva_alivec = 0
            for i, vrh in enumerate(self.vrhovi):
                if i == izbrani:
                    if vrh-odstranjenih > 1:
                        dva_alivec += 1
                else:
                    if vrh > 1:
                        dva_alivec += 1
            if dva_alivec == 0:
                izbrani = self.vrhovi.index(max(self.vrhovi))
                vrhov_z1 = sum(v == 1 for v in self.vrhovi)
                if vrhov_z1%2 == 1:
                    odstranjenih = self.vrhovi[izbrani]-1
                else:
                    odstranjenih = self.vrhovi[izbrani]
                    
        if odstranjenih == 0:
#.........这里部分代码省略.........
开发者ID:Januar1,项目名称:nim_game,代码行数:103,代码来源:nim.py

示例8: __init__

# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import destroy [as 别名]
class ClassifyImage:

    def __init__(self, master, parentWindow):
        
        frame = Frame(master)
        frame.pack()
        self.frame = frame

        # for destroy purpose
        self.master = master

        self.parentWindow = parentWindow
        
        # database with images
        self.imgDB = tm.cdb.imgDB
        # for database.get(item)
        self.item = 1
        
        self.labelImgPlace = Label(frame,
                                   text="Image from database \n (click next)")
        self.labelImgPlace.grid(row=0, column=1)

        # buttons for going trought imgDB
        self.buttonNext = Button(frame, text="Next",
                                 command=self.next)
        self.buttonNext.grid(row=2, column=0)

        self.buttonBack = Button(frame, text="Back",
                                 command=self.back)
        self.buttonBack.grid(row=3, column=0)

        # label for name of class
        self.varForLabel = StringVar()
        self.labelClassName = Label(frame, textvariable=self.varForLabel)
        self.labelClassName.grid(row=4, column=0)

        self.button = Button(frame, text="load image",
                             command=self.load_image)
        # self.button.grid(row=0, column=0)
        
        self.label = 0
        # self.label=Label(frame,image=imgP)
        # self.label.pack(side=RIGHT)
        
        self.things = self.parentWindow.childResultList  # ["cup","banana","pencil"]
        
        for i in range(len(self.things)):
            b = Radiobutton(self.frame, text=self.things[i], value=i)
            # write i-ths element from list to database as label 
            b.config(command=lambda iter=i: self.choice_class(iter))
            b.deselect()
            b.grid(row=i+1, column=2)
    
    def next(self):

        self.item = self.item + 1
        try:
            self.load_image_from_entry(self.item)
        except:
            print("end of imgDB")
            self.item = 1

    def back(self):
        self.item = self.item-1
        try:
            self.load_image_from_entry(self.item)
        except:
            print("begin of imgDB")
            self.item = 1

    def choice_class(self, labelIter):
        
        # change entry.imgLabel
        entry = self.imgDB.get(self.item)
        entry.imgLabel = labelIter
        self.varForLabel.set(entry.imgLabel)
        self.parentWindow.childData = self.things[labelIter]
        # self.master.destroy()
        
    def load_image_from_entry(self, item):
        
        entry = self.imgDB.get(item)
        
        # import label
        self.varForLabel.set(entry.imgLabel)
        
        # import image 
        img = pickle.loads(entry.imgOrign.encode('latin1'), encoding='latin1')
        img = Image.fromarray(img)
        imgP = ImageTk.PhotoImage(img)
        
        # delite old image from view
        if self.label:
            self.label.destroy()
        
        self.label = Label(self.frame, image=imgP)  # ,height=1500,width=1500
        self.label.image = imgP
        self.label.grid(row=0, column=1)
    
    def load_image(self):
#.........这里部分代码省略.........
开发者ID:valdecar,项目名称:faceRepresentWithHoG,代码行数:103,代码来源:gui.py


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