0

This is exercise 19.3 from Think Python of Allen Downey. The code is suppose to get the color of the entry widget and change the background color of the circle. I have no idea why after clicking the button the code returns an error Tclerror: unknown option "-fill". It is strange as the book itself provide exactly the same solution. Is something wrong with the configuration of my Python? No idea. Please help.

from swampy.Gui import *

g = Gui()
g.title = ('Gui')

canvas = g.ca(width=500, height=500)
canvas.config(bg='white')
circle = None

def make_circle():
    global circle
    circle = canvas.circle([0,0], 100, fill='red')

def change_color():
    if circle == None:
        return
    my_color = entry.get()
    my_circle.config(fill=my_color)


my_circle = g.bu(text='Make circle', command = make_circle)
entry = g.en(text='Any text', bg = 'blue')
g.bu(text='Change color', command = change_color)

g.mainloop()
halny
  • 63
  • 6
  • 1
    you do `my_circle.config(fill=my_color)`, but `my_circle` seems to be your Button and not your canvas item, that's `circle`. – fhdrsdg Dec 13 '18 at 08:31
  • 1
    Also I don't know what this `swampy.Gui` is exactly, but if you think you're ready for it I'd really recommend learning real Tkinter instead of using this simplified interface module. – fhdrsdg Dec 13 '18 at 08:34
  • @fhdrsdg - Thank you. I must have been blind when I was looking at it. Btw swampy.Gui is a suite of Python programs for use with "Think Python" book of Allen Downey. It includes implementation of turtle graphics used to teach procedural interface design and OOP but perheps you are right and I shall reconsider start learning real Tkinter instead – halny Dec 13 '18 at 09:12
  • 1
    Well by the looks of it, this module is a "dumbed down" version of Tkinter. Thuis might be useful to get the basic concepts, but you don't seem to have any control over widget placement, which is very important in making real GUI's. Also a lot of object/method names are slightly different, which might make it hard to transition to real Tkinter when you learn this too much. – fhdrsdg Dec 13 '18 at 09:36

0 Answers0