Closed Thread
Results 1 to 4 of 4

Thread: BEGGINER problem

  1. #1
    icystef is offline Newbie
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    BEGGINER problem

    Hi i'm a begginer i'm making a program and i im encountering a little problem first here is my code :

    Code:
    #othello projet prog
    
    from tkinter import *
    from random import randrange
    
    #interface graphique
    
    def couleurAlea():  
        global couleur
        alea =['yellow','cyan','blue','green','grey','purple','orange','pink','dark green','red']
        c = randrange(10)
        couleur = alea[c]
        can1.configure(bg=couleur)
    
    def creerTable():
        global x1, y1, x2, y2
        v=0
        h=0
        while (v < 9) :                                                        # verticales
            can1.create_line(x1,y1,x2,y2, width = 5 , fill='black')
            x1 = x1 + 70
            x2 = x2 + 70
            v = v + 1       
        while (h < 9) :                                                        #horizontales
            if( h == 0) :
                x1, y1, x2, y2 = 700, 565, -700, 565
            can1.create_line(x1,y1,x2,y2, width = 5 , fill='black')
            y1 = y1 - 70
            y2 = y2 - 70
            h = h + 1
    
    
    
    def detruireRegles():
        fen2.destroy
        bou3.configure(state=NORMAL)
           
    def regles():
                bou3.configure(state=DISABLED)
                fen2 = Tk()
                fen2.configure(height=500,width=500)
                tex2 = Label(fen2, text='REGLES DU JEU',fg='blue',height=0,width=0)
                tex2.pack(side=TOP)
                txtreg = Label(fen2, text='Othello est un jeu de strat&#233;gie &#224; deux joueurs : Noir et Blanc. Il se joue sur un plateau\n unicolore de 64 cases, 8 sur 8, appel&#233; othellier. Ces joueurs disposent de 64 pions\nbicolores, un cote et blancs de l autre. Par commodite, chaque joueur a devant\nlui 32 pions mais ils ne lui appartiennent pas et il doit en donner &#224; son adversaire si\ncelui-ci n en a plus. Un pion est noir si sa face noire est visible et blanc si sa face\nblanche est sur le dessus.   ',fg='black')
                txtreg.pack()              
                bou5 = Button(fen2, text='Fermer fenetre', bg='orange', command = fen2.destroy)            # doit utiliser detruireRegles : bug le bouton Regles ne se desactive pas com prevu apres lavoir clique
                bou5.pack(side=BOTTOM)
                
                       
    
    x1, y1, x2, y2 = 5, 582, 5 , -582                      # coordonees des droites formant la table
    fen1 = Tk()
    can1 = Canvas(fen1,bg='dark green',height=566.2,width=566.2)
    can1.pack(side=LEFT)
    tex1 = Label(fen1, text='Bienvenue dans othello!', fg='blue')
    tex1.pack()
    bou1 = Button(fen1, text='Nouvelle Partie',command = creerTable) 
    bou1.pack()
    bou2 = Button(fen1, text='Changer couleur plateau',command = couleurAlea)
    bou2.pack()
    bou3 = Button(fen1, text='Regles du jeu', command = regles)
    bou3.pack()
    bou4 = Button(fen1, text='Quitter',command = fen1.destroy) 
    bou4.pack()
    fen1.mainloop()
    What i want is this line :

    bou5 = Button(fen2, text='Fermer fenetre', bg='orange', command = fen2.destroy)
    (in my 4th function)

    i want this button to close WIndow 2 and set NORMAL state on button3 with is a window defined in the main program. Probmel is that if i put ( command = detruireRegles ) #(my second fonction)
    it says that fen2 is not defined. SO that means i would need to put 2 commands in the command field but i don't know if there is another way then making a function and this one here for me is not working with this methods.

    Thanks for your help. Stef

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: BEGGINER problem

    You can either pass fen2 as an argument to detruireRegles():
    Code:
    bou5 = Button(fen2, text='Fermer fenetre', bg='orange', command = detruireRegles(fen2))
    Then keep detruireRegles the same, or alternatively you can make detruireRegles a locally scoped function, like this:
    Code:
    def regles():
                bou3.configure(state=DISABLED)
                fen2 = Tk()
                fen2.configure(height=500,width=500)
                tex2 = Label(fen2, text='REGLES DU JEU',fg='blue',height=0,width=0)
                tex2.pack(side=TOP)
                txtreg = Label(fen2, text='Othello est un jeu de strat&#233;gie &#224; deux joueurs : Noir et Blanc. Il se joue sur un plateau\n unicolore de 64 cases, 8 sur 8, appel&#233; othellier. Ces joueurs disposent de 64 pions\nbicolores, un cote et blancs de l autre. Par commodite, chaque joueur a devant\nlui 32 pions mais ils ne lui appartiennent pas et il doit en donner &#224; son adversaire si\ncelui-ci n en a plus. Un pion est noir si sa face noire est visible et blanc si sa face\nblanche est sur le dessus.   ',fg='black')
                txtreg.pack()  
                def detruireRegles():
                    fen2.destroy
                    bou3.configure(state=NORMAL)
                bou5 = Button(fen2, text='Fermer fenetre', bg='orange', command = detruireRegles)            # doit utiliser detruireRegles : bug le bouton Regles ne se desactive pas com prevu apres lavoir clique
                bou5.pack(side=BOTTOM)
    That should work as well, and is preferable if you're not using that function anywhere else other then in regles.
    Wow I changed my sig!

  4. #3
    icystef is offline Newbie
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Re: BEGGINER problem

    Oh thanks ! First method didn't seem to work really good but the second one is working really good thanks !!

    One more question You see the purpose of that function was to 'disable' the 'Rules' button in order to forbid the user to open a infinite number of help windows , and then when you hit bou5 it closes help window and reanables the 'Rules buton' on main frame. THe problem is that it works when user exits 'Rules' windows by clicking on bou5 , but if he clicks the X at the top right of the window it will close the window and then the 'Rules' button will remain disabled forever Is there a way to name the X button in order for him to do same action as bou5 ?

    Thank you very much for your help =)

  5. #4
    icystef is offline Newbie
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Re: BEGGINER problem

    Solved ! thx anyay =)

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. C# Begginer Tutorial -Easy to Learn
    By Davide in forum CSharp Tutorials
    Replies: 12
    Last Post: 01-30-2012, 07:30 AM
  2. C# best book for begginer
    By sunilkumar in forum C# Programming
    Replies: 5
    Last Post: 07-16-2011, 04:03 PM
  3. If problem or cout problem?
    By chaoticape in forum C and C++
    Replies: 4
    Last Post: 06-10-2011, 10:29 AM
  4. Replies: 1
    Last Post: 01-04-2011, 10:06 AM
  5. Begginer In need of pseudocode tutorial help
    By jason007thomas in forum Introductions
    Replies: 9
    Last Post: 11-07-2008, 05:03 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts