0

Ive researched my question here, Python Tkinter buttons, and here, Setting the position on a button in Python?

Sadly, I'm still stuck. I'm making a game inspired by the game angry red button.

I'm attempting to have a second button placed next to a first one, which python autonomatically places in the top center of the screen.

When I run the code pasted below, no additional button appears. See screen shot below, Screen Shot

Here is my attempt using pack (seen toward the bottom of the code).

from tkinter import *
s = 0
def kill():
  cnv.color('red')
def talk():
  global s
  if s == 0:
      cnv.create_text(100,20,text='why, hello there!', font='Times')
      s += 1
  elif s == 1:
      cnv.create_text(100,40,text='my name is Phill!', font='Courier')
      s += 1
  elif s == 2:
      cnv.create_text(100,60,text='why are you clicking me?', font='Times')
      s += 1
  elif s == 3:
      cnv.create_text(100,80,text='that kinda hurts...', font='Arial')
      s += 1
  elif s == 4:
      cnv.create_text(100,100,text='ok, what do you want?', font='Courier')
      s += 1
  elif s == 5:
      cnv.create_text(145,130,text='seriously, stop that!', font=('Arial',28), fill='red')
      s += 1
  elif s == 6:
      cnv.create_text(100,160,text='...', font='Times')
      s += 1
  elif s == 7:
      cnv.create_text(100,180,text='You know what?', font='Courier')
      s += 1
  elif s == 8:
      cnv.create_text(100,200,text="You wanna go?", font='Courier')
      s += 1
  elif s == 9:
      cnv.create_text(105,220,text='OK!!!', font=('Arial',28), fill='red')
      v = Button(tk, text="Death",command=kill)
      v.pack(side="right")
      l = Button(tk, text="Death",command=kill)
      l.pack(side="left")
      s += 1
tk = Tk()
btn = Button(tk, text="Phill",command=talk,width=10,height=10)
btn.pack()
cnv = Canvas(tk, width=1000, height=700)
cnv.pack()

Any ideas how to make this work with pack, or perhaps with grid?

Community
  • 1
  • 1

1 Answers1

0

use .pack(side=LEFT) for example, or whatever side you want. I suggest experimenting with this.

Amit Gold
  • 727
  • 7
  • 22
  • Thank you! I got it to work using pack as you suggested. I can position buttons top, bottom, right or left. Now, I have the next problem, which I will create in a new thread (I'm not able to create a new button by pushing the original button) – Chicken Code Feb 21 '16 at 22:32