почему этот код не работает?Я пытаюсь получить кнопку для вызова функции clickGame.Он открывает функцию clickGame в новом окне, но ничего не происходит, и я получаю сообщение об ошибке.Он работает без функции кнопки, когда я нажимаю «enter to play clickGame»
Я не понимаю, что означает ошибка атрибута, когда я пробую ее с помощью функции кнопки: я продолжаю получать это сообщение об ошибке:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ejoyc\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Users\ejoyc\Desktop\Final Project\FinalProjectTest.py", line 26, in clickGame
center = Text(Point(10,80), "Click to create a circle")
File "C:\Users\ejoyc\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 3095, in __init__
Widget.__init__(self, master, 'text', cnf, kw)
File "C:\Users\ejoyc\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 2286, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Users\ejoyc\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 2256, in _setup
self.tk = master.tk
AttributeError: 'Point' object has no attribute 'tk'
Мой код:
from graphics import*
from random import randint
import random
from tkinter import *
from tkinter import ttk
##
##def getInfo(): # draw button here
## clickGame = input("Press <enter> to play clickGame: ")
## print()
def clickGame():
win = GraphWin("Circle Game", 800, 800)
win.setCoords(-100, -100, 100, 100)
win.setBackground("white")
center = Text(Point(10,80), "Click to create a circle")
center.draw(win)
win.getMouse() # waits for mousclick to get score
#i = 50
score = 0
for i in range(20):
p = win.getMouse()
x = p.getX()
y = p.getY()
color = ("magenta","skyblue","purple","pink", "green", "violet", "cyan")
color = random.choice(color)
if color == "magenta":
score = score + 10
elif color == "skyblue":
score = score + 10
elif color == "purple":
score = score + 10
elif color == "pink":
score = score + 10
elif color == "green":
score = score + 10
elif color == "violet":
score = score + 10
elif color == "cyan":
score = score + 10
# draw score on screen
# score overlaps
points = Text(Point(10,90), "Score: %s" %score)
points.draw(win)
circle = Circle(Point(x, y), randint(10, 40))
circle.setFill(color)
circle.draw(win)
def getButton():
root = Tk()
root.title("MainMenu")
# ttk.Button(root, text = "ClickGame", command = clickGame).grid()
# ttk.Button.pack()
button1 = Button(root, text = "clickGame", command = clickGame)
button1.pack()
root.mainloop()
def main():
getButton()
## getInfo()
## if clickGame == clickGame:
## clickGame() #calls the clickGame
##
main()