zelle-graphics

python graphics win.getKey() function?

我怕爱的太早我们不能终老 提交于 2021-01-29 03:26:38
问题 I am new to python and trying to make a game where an object moves left/right according to the arrow keys on the keyboard. I've seen different methods to do this through importing turtle, curse, etc., but how do I do this using only win.getKey() ? So far I have this, but it isn't working: while True: k = win.checkKey() if k == 'Left': object.move(-dx, dy) elif k == 'Right': object.move(dx, dy) elif k == 'period': break 回答1: Since you only provided a fragment of code, I'm going to make some

python graphics win.getKey() function?

杀马特。学长 韩版系。学妹 提交于 2021-01-29 03:19:20
问题 I am new to python and trying to make a game where an object moves left/right according to the arrow keys on the keyboard. I've seen different methods to do this through importing turtle, curse, etc., but how do I do this using only win.getKey() ? So far I have this, but it isn't working: while True: k = win.checkKey() if k == 'Left': object.move(-dx, dy) elif k == 'Right': object.move(dx, dy) elif k == 'period': break 回答1: Since you only provided a fragment of code, I'm going to make some

How to undraw plot with Zelle graphics?

删除回忆录丶 提交于 2020-01-17 12:41:59
问题 This is a code problem for Python 3.5.2 using John Zelle's graphics.py : I have spent a good amount of time looking for the answer here, but just can not figure it out. The function undraw() exists just like getMouse() . But it seems like it do not work for the plot() command, only the draw() command. What am I doing wrong? And how can I keep the window open, but erase the previous the plot before the next one is drawn? pdf documentation for the functions of graphics : http://mcsp.wartburg

How to undraw plot with Zelle graphics?

人盡茶涼 提交于 2020-01-17 12:41:05
问题 This is a code problem for Python 3.5.2 using John Zelle's graphics.py : I have spent a good amount of time looking for the answer here, but just can not figure it out. The function undraw() exists just like getMouse() . But it seems like it do not work for the plot() command, only the draw() command. What am I doing wrong? And how can I keep the window open, but erase the previous the plot before the next one is drawn? pdf documentation for the functions of graphics : http://mcsp.wartburg

How can I make this fractal render faster in Zelle graphics?

泄露秘密 提交于 2019-12-24 00:48:15
问题 This takes over an hour to render this mandelbrot set with only 100 iteration and has taken 10 hours with 10,000 iterations. Is there a way to make it faster: from graphics import * width = 700 height = 700 win = GraphWin("Mandelbrot",width,height) spacing = 1 zoom = 0.1 xOffset = -0.171 yOffset = 0.61 win.setBackground('black') for x in range(0,width,spacing): for y in range(1,height,spacing): a = ((x / width) * zoom) - xOffset b = ((y / height) * zoom) - yOffset pt = Point(x,y) n = 0 ca = a

Python: source code string cannot contain null bytes

人盡茶涼 提交于 2019-12-17 16:27:32
问题 I'm using Max OS X 10.10.3, and I finally got the graphics.py to show in Python 3, before it was saying no module existed. However, now when I try import graphics , or from graphics import * , I get the message: "source code string cannot contain null bytes" Does any Mac user (using Python 3) perhaps know what is wrong? Has anyone used the Zelle book and his graphics.py module? Thanks. 回答1: For posterity: I had the same problem and fixed it using, sed -i 's/\x0//g' FILENAME The file seemed to

Get color of coordinate of figure drawn with Python Zelle graphics

孤街醉人 提交于 2019-12-11 06:22:20
问题 In python, How can I get the color of a specific coordinate of any figure, that I've drawn with the Zelle graphics module? I'm using Python with the Zelle graphics module to process with my circles and lines. I'm trying to get a color of aspecific coordinate (or pixel?) on the canvas I'm drawing on. What method or other modules do I have to use in order to achieve this? I thought the getPixel() method would work, but it does not since it's for image processing, not for drawn pictures. My

Detect if you click inside a box in Python Zelle graphics

前提是你 提交于 2019-12-08 14:18:13
问题 I have created a dice betting game. When my code is run, there is a "CLICK TO ROLL" button. Currently, if you click anywhere on the screen, the dice will roll. How can I make it so the program closes if you click anywhere outside the box, and only if you click inside the box the dice rolls? import graphics from graphics import * from random import randrange max_x = 500 max_y = 300 win = GraphWin("Dice Rolls", max_x,max_y) #drives the program def main(): class dots(): #Drawn dots def __init__

How do I implement collision detection?

﹥>﹥吖頭↗ 提交于 2019-12-02 13:24:27
from graphics import* import time import random def main(): numx=random.randint(10,700) wn=GraphWin("AK",700,700) wn.setBackground("white") msg=Text(Point(25,30),"Score") msg.setSize(12) msg.setTextColor('blue') msg.draw(wn) inch=Entry(Point(60,30),2) inch.setFill('white') inch.draw(wn) sqrg=Rectangle(Point(330,650),Point(430,665)) sqrg.setFill("red") sqrg.draw(wn) blx=Circle(Point(numx,80),20) blx.setFill("blue") blx.draw(wn) xval=10 yval=0 wn.getMouse() for i in range(150): sqrg.move(xval,yval) symbl=wn.checkKey() if symbl=="Right": xval=10 yval=0 if symbl=="Left": xval=-10 yval=0 time.sleep

Python: source code string cannot contain null bytes

三世轮回 提交于 2019-11-27 14:44:43
I'm using Max OS X 10.10.3, and I finally got the graphics.py to show in Python 3, before it was saying no module existed. However, now when I try import graphics , or from graphics import * , I get the message: "source code string cannot contain null bytes" Does any Mac user (using Python 3) perhaps know what is wrong? Has anyone used the Zelle book and his graphics.py module? Thanks. DilithiumMatrix For posterity: I had the same problem and fixed it using, sed -i 's/\x0//g' FILENAME The file seemed to be messed up in numerous ways (wrong endings, etc); no idea how... See https:/