[Tutor] Traffic Light
anthonym
anthonym at att.net
Sun Jan 20 00:29:08 CET 2013
Sure thing. Here is the code. And after that is the box I get with the
radio buttons but no shapes.
from tkinter import * # Import tkinter
class Trafficlight:
def __init__(self):
window = Tk() # Create a window
window.title("Traffic Light") # Set a title
# Place canvas in the window
self.canvas = Canvas(window, width = 480, height = 480, bg =
"white")
self.canvas.pack()
# Add three radio buttons to frame1
frame1 = Frame(window) # Create and add a frame to window
frame1.pack()
self.v1 = IntVar()
self.v2 = IntVar()
rbRed = Radiobutton(frame1, text = "Red", bg = "red",
variable = self.v2,
value = 1,
command = self.processRadiobutton)
rbYellow = Radiobutton(frame1, text = "Yellow", bg = "yellow",
variable = self.v2, value = 2,
command = self.processRadiobutton)
rbGreen = Radiobutton(frame1, text = "Green", bg = "green",
variable = self.v2, value = 3,
command = self.processRadiobutton)
rbRed.grid(row = 400, column = 1)
rbYellow.grid(row = 400, column = 2)
rbGreen.grid(row = 400, column = 3)
window.mainloop() # Create an event loop
# Display a rectangle
def displayRect(self):
self.canvas.create_rectangle(10, 10, 100, 100, tages = "rect")
# Display a Oval for the top light
def displayOval(self):
self.canvas.create_oval(10, 10, 10, 10)
# Display an Oval for the middle light
def displayOval(self):
self.canvas.create_oval(20, 20, 20, 20)
# Display an Oval for the bottom light
def displayOval(self):
self.canvas.create_oval(30, 30, 30, 30)
# Add Radio Button process below once I figure that out
def processRadiobutton(self): pass
Trafficlight()
from tkinter import * # Import tkinter
class Trafficlight:
def __init__(self):
window = Tk() # Create a window
window.title("Traffic Light") # Set a title
# Place canvas in the window
self.canvas = Canvas(window, width = 480, height = 480, bg =
"white")
self.canvas.pack()
# Add three radio buttons to frame1
frame1 = Frame(window) # Create and add a frame to window
frame1.pack()
self.v1 = IntVar()
self.v2 = IntVar()
rbRed = Radiobutton(frame1, text = "Red", bg = "red",
variable = self.v2,
value = 1,
command = self.processRadiobutton)
rbYellow = Radiobutton(frame1, text = "Yellow", bg = "yellow",
variable = self.v2, value = 2,
command = self.processRadiobutton)
rbGreen = Radiobutton(frame1, text = "Green", bg = "green",
variable = self.v2, value = 3,
command = self.processRadiobutton)
rbRed.grid(row = 400, column = 1)
rbYellow.grid(row = 400, column = 2)
rbGreen.grid(row = 400, column = 3)
window.mainloop() # Create an event loop
# Display a rectangle
def displayRect(self):
self.canvas.create_rectangle(10, 10, 100, 100, tages = "rect")
# Display a Oval for the top light
def displayOval(self):
self.canvas.create_oval(10, 10, 10, 10)
# Display an Oval for the middle light
def displayOval(self):
self.canvas.create_oval(20, 20, 20, 20)
# Display an Oval for the bottom light
def displayOval(self):
self.canvas.create_oval(30, 30, 30, 30)
# Add Radio Button process below once I figure that out
def processRadiobutton(self): pass
Trafficlight()
On 1/19/13 3:14 PM, "Matthew Ngaha" <chigga101 at gmail.com> wrote:
>On Sat, Jan 19, 2013 at 10:56 PM, anthonym <anthonym at att.net> wrote:
>> Thanks again for the info Alan. I am still passing the button process
>> until I can get my rectangle and ovals on the canvass. The program runs
>> and produces a window with the radio buttons on top. I would like them
>>on
>> the bottom but changes to the row field have no effect.
>>
>> Anybody have any ideas on why I don't see my shape on the canvass?
>
>i doubt i can help, but it might help if you could paste the section
>of the code in relation to what you're explaining and tell us what
>it's doing? some people don't use tkinter so its a bit hard to
>understand what you're saying.
>_______________________________________________
>Tutor maillist - Tutor at python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list