0

I am making a basic tictactoe game in tkinter, in Python 3.5.3 but I ran into an error saying .pack() was an invalid syntax. Code:

from tkinter import *
root = Tk()
turn = X
1 = Button(root, command=Pressed)
1.pack()
def Pressed():
    pass
root.geometry('900x900')
root.mainloop()

Please could someone give me an answer.

Right leg
  • 13,581
  • 5
  • 36
  • 68
  • 1
    Here is the grammar of the valid identifiers: https://stackoverflow.com/a/10120327/7051394 – Right leg Sep 05 '17 at 09:16
  • Why can't variable names start with numbers? https://stackoverflow.com/questions/342152/why-cant-variable-names-start-with-numbers – Kenly Sep 05 '17 at 13:58

1 Answers1

0

You are assigning an invalid variable name for your button. Try rewrite

1 = Button(root, command=Pressed)
1.pack()

To something like:

button_1 = Button(root, command=Pressed)
button_1.pack()

Note on variable names:

  • Must begin with a letter (a - z, A - B) or underscore (_)

  • Other characters can be letters, numbers or _

  • Case Sensitive

  • Can be any (reasonable) length

  • There are some reserved words which you cannot use as a variable name because Python uses them for other things.

Szabolcs
  • 3,041
  • 13
  • 31
  • It solves the pack problem but now it says I haven't defined Pressed() – Guydangerous99 Sep 08 '17 at 16:39
  • Yeah, because you assign `Pressed` before it's declared so you should put the `def Pressed()` block before `button_1 = Button(...` and then it should work. – Szabolcs Sep 09 '17 at 19:57