Re: Tkinter help, please...

2007-05-24 Thread Medi Ochre
John McMonagle wrote:
> I've made a couple of minor changes to your code from the Cribbage class 
> down:
> 
> class Cribbage:
>  def __init__(self, win):
> 
...
>  score = run.play()
>  if score >= best: best = score
>  time.sleep(1)  <--- short sleep to see what's happening
>  win.mainloop()
> 
> main()
> 
> 
> 
> Regards,
> 
> John
Thank you, Mr. McMonagle!

-- 
Posted via a free Usenet account from http://www.teranews.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter help, please...

2007-05-24 Thread John McMonagle
I've made a couple of minor changes to your code from the Cribbage class 
down:

class Cribbage:
  def __init__(self, win):

  self.parent = win# < make the toplevel Tk window an
   # < attribute of the class
  #Draw the interface
  self.f = Frame(self.parent)
  self.f.grid()
  self.cardpix = [Label(self.f), Label(self.f), Label(self.f), 
Label(self.f), Label(self.f)]
  clr = ["red", "blue"]
  n = 1
  for c in self.cardpix:
  c.configure(width=10, height=10, bg=clr[n%2], text="card 
"+str(n))
  c.grid(row=0, column=n-1)
  n += 1
  self.scorebox = Label(self.f)
  self.scorebox.configure(height=5, bg="green", text="Score: 0")
  self.scorebox.grid(row=1, column=0, columnspan=5)

  def play(self):
  d = Deck()
  hand = [d.deal(), d.deal(), d.deal(), d.deal()]
  flipped = d.deal()
  hand.append(flipped)
  hand.sort()
  score = tally(hand, flipped)
  self.scorebox.configure(text= "Score: " + str(score))
  #Eventually, display the actual card images, but for now...
  for c, x in zip(hand, self.cardpix):
  x.configure(text = str(c))
  #I've tried both of these, to no avail.
  self.parent.update()< update the toplevel window
  return score

def main():
  win = Tk()
  run = Cribbage(win)
  score = 0
  best = 0
  while score < 24:
  score = run.play()
  if score >= best: best = score
  time.sleep(1)  <--- short sleep to see what's happening
  win.mainloop()

main()



Regards,

John
-- 
http://mail.python.org/mailman/listinfo/python-list