Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Nicholas Cage
Courses Plus Student 30 PointsHow do I hide my ovals
I am creating a game and I have 4 lines and an algorithm to make a quite similar game to tic tac toe. I want to hide all 9 ovals on the canvas in the beginning and then have them show up as they're clicked and then be painted to a certain color when clicked which I plan to use the colors to make it a 2 player game so it paints black for example for 1st, 3rd, 5th, 7th and 9th clicks and yellow for example for the 2nd, 4th, 6th and 8th clicks. I have tried oval.destroy and canvas.itemconfig(oval, state='hidden'), but still no luck. Please help me Here is my code: import Tkinter
root = Tkinter.Tk() root.wm_title('tic-tac-toe') start = root canvas = Tkinter.Canvas(root, width=300, height=300, background='white') canvas.grid(row=1, rowspan=2, column=1) canvas.pack() btn1= Tkinter.Button(root, bg='white', command =canvas.delete("all"), text = 'exit') canvas.focus_set()
r = 40 x1 = 0 x2 = 300 for z in range(0, 300, 100): y1 = z y2 = z canvas.create_line(x1, y1, x2, y2) y1 = 0 y2 = 300 for z in range(0, 300, 100): x1 = z x2 = z canvas.create_line(x1, y1, x2, y2) for x in range(10, 300, 100): for y in range(10, 300, 100): canvas.create_oval(x, y, x + 2*r, y + 2*r)
def closewindow(): exit() oval=canvas.create_oval oval.destroy()
root.mainloop()
1 Answer
Oszkár Fehér
Treehouse Project ReviewerI am working to in tkinter, I am not an expert in tkinter, but I built some pritty nice applications and in my experience it should be built in a class, the truth is, i never tried to build without creating a class. I tried to see what you are building, this is all the code for this game? If you want, send me the code on email if there is more.(feheroszkar@yahoo.com) and i will try to help you. Happy codiing