vendredi 30 décembre 2016

If loop in tkinter - button pressed

How to get tkinter to enter the if loop when button pressed to print? I do not want the print command to be in the button function. Please help

Code:

from tkinter import *

class Player:
   N = 0
   def __init__(self, name, points):
    # instance variables goes here
    self.name   = name
    self.score  = points
    # increment class variable
    Player.N      = Player.N+1

class G_501:

  def __init__(self,players=[]):
    self.NoPlayers = len(players)
    print("Number of players",self.NoPlayers)
    Spillere = []
    Score = []
    Runde = 0


    for i in range(0,len(players)):
        P = Player(players[i],501)
        print("Player",Player.N,P.name,"- Point:",P.score)
        Spillere.append(P.name)
        Score.append(P.score)
        Score = list(map(int, Score))


    root = Tk()
    c = [False]

    def half_bull(c,event=None):
        c.append(True)
        return c

    b1 = Button(root, text="Half Bull", bg="green", fg="black", command=lambda c=c: half_bull(c))
    b1.pack()

    print(c)
    if c[-1] == True:
        print("Fedt")

    root.mainloop()

S = G_501(["Chr"])

Only need help with the tkinter part... Please help!

Aucun commentaire:

Enregistrer un commentaire