Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 4th, 2012, 09:55 PM
sean2012 sean2012 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 sean2012 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 16 m 19 sec
Reputation Power: 0
Tkinter Canvas

Hello I am trying to make a simple program that will move the turtle specified by the keyboard input and I would like to have a list of controls on the right. This is my code so far
Code:
from turtle import *
import tkinter

key1 = 1

Controls = tkinter.Tk()
Controls.title("Color")
Controls.minsize(100, 100)
cv = tkinter.Canvas(Controls, bg = "gray")
cv.pack(side = tkinter.LEFT)
t = RawTurtle(cv)
t.pensize(3)

w = tkinter.Label(Controls, text="Arrow Keys - Move")
w.pack()

def k1():
    global key1
    key1 +=1
    while key1 % 2 == 0:
        t.pencolor(random.choice(colors))
        t.forward(5)

onkey(k1, "Up")

listen()
mainloop()


I don't think I am implementing the Canvas correctly.

Reply With Quote
  #2  
Old December 5th, 2012, 12:00 AM
dwblas dwblas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 294 dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 18 h 53 m 25 sec
Reputation Power: 7
Your code modified to print which key was pressed, Up, Down, etc. And a tutorial on the Canvas module
Code:
def to_key(event):
    print event.keysym

key1 = 1

Controls = tkinter.Tk()
Controls.title("Color")
Controls.minsize(100, 100)
Controls.bind("<KeyPress>", to_key)
#cv = tkinter.Canvas(Controls, bg = "gray")
#cv.pack(side = tkinter.LEFT)
#t = RawTurtle(cv)
#t.pensize(3)

w = tkinter.Label(Controls, text="Arrow Keys - Move")
w.pack()

def k1():
    global key1
    key1 +=1
    while key1 % 2 == 0:
        t.pencolor(random.choice(colors))
        t.forward(5)

#onkey(k1, "Up")

#listen()
Controls.mainloop() 

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Tkinter Canvas

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap