Python 2.7 tkSimpleDialog pycharm
我正在为一个学校项目编写代码,并试图在代码中使用tkinter,但它不断出现错误。我正在使用mac笔记本电脑和pycharm界面Python 2.7 tkSimpleDialog pycharm,python-2.7,tkinter,Python 2.7,Tkinter,我正在为一个学校项目编写代码,并试图在代码中使用tkinter,但它不断出现错误。我正在使用mac笔记本电脑和pycharm界面 Traceback (most recent call last): File "/Users/-----/Desktop/python/Tkinter turtle obstacle.py", line 20, in <module> color1()#does it automatically File "/Users/-----/De
Traceback (most recent call last):
File "/Users/-----/Desktop/python/Tkinter turtle obstacle.py", line 20, in <module>
color1()#does it automatically
File "/Users/-----/Desktop/python/Tkinter turtle obstacle.py", line 8, in color1
ac1 = Sd("Color Selector", 'Enter the color of the turtle')
TypeError: 'module' object is not callable
tkSimpleDialog是一个模块,而不是一个类。 您可能希望在此模块中创建类的实例
在模块中查找类,并使用正确的类创建实例。您所说的@PaperAZO79是什么意思
import turtle # 1. import the modules
import random
import Tkinter as tk
import tkSimpleDialog as Sd
def color1():
ac1 = Sd("Color Selector", 'Enter the color of the turtle')
steve.color(ac1)
print(5)
def color2():
ac2 = Sd("Color Selector", 'Enter the color of the obstacle')
sam.color(ac2)
root = tk.Tk()
wn = turtle.Screen() # 2. Create a screen
wn.bgcolor('white')
steve = turtle.Turtle() # 3. Create two turtles
sam = turtle.Turtle()
color1()#does it automatically
color2()
red = tk.Button(root, text = "Enter String", command = color1)#this puts it on a button click
blue = tk.Button(root, text = "Enter String", command = color2)
red.grid(row=0,column=0)
blue.grid(row=1,column=0)
steve.shape('turtle')
sam.shape('circle')
steve.speed(1)
sam.speed(1)
steve.pensize(5)
sam.pensize(25)
sam.penup()
sam.pendown()
steve.penup()
steve.goto(-300,0)
sam.goto(0,0)
b = True
while b is True:
steve.pendown()
steve.forward(20)
if steve.xcor() == sam.xcor() -40:
steve.left(90)
steve.forward(30)
steve.right(90)
if steve.xcor() == sam.xcor() +40:
steve.right(90)
steve.forward(30)
steve.left(90)
if steve.xcor() == 200:
steve.write('Obstacle Avoided', font=('Arial', 20, "bold"))
break
wn.exitonclick()