#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    85
    Rep Power
    1

    [Python 2.7 + Tkinter] Arc Color Generator, Error Found!


    Hey Python Users...

    I try to figure out, how i can create programs to generate as example things like shapes, colors,
    patterns, etc....

    So i do my first try on it, to write an color arc generator in tkinter, used python 2.7 on an older windows
    system yet...


    So this is my script:
    Code:
    from Tkinter import *
    
    class Window(Frame):
    
        def __init__(self, master=None):
    
            self.master = master
    
            Frame.__init__(self, master)
    
            self.init_window()
    
    
    
        def init_window(self):
    
            self.master.title('Canvas')
            
            self.e_x1 = Entry(self.master)
            self.e_y1 = Entry(self.master)
            self.e_x2 = Entry(self.master)
            self.e_y2 = Entry(self.master)
            self.e_tell = Entry(self.master)
            self.e_b = Button(self.master, text = "Create Line", command = self.Create)
    
            self.e_x1.pack(fill = X, side = TOP)
            self.e_y1.pack(fill = X, side = TOP)
            self.e_x2.pack(fill = X, side = TOP)
            self.e_y2.pack(fill = X, side = TOP)
            self.e_tell.pack(fill = X, side = TOP)
            self.e_b.pack(fill = X, side = TOP)
    
            self.w = Canvas(self.master, height = 512, width = 512)
            self.w.pack(side = TOP)
    
    
    
    
        def Create(self):
    
            colors = ['red', 'orange', 'yellow', 'lime', 'green', 'aqua', 'cyan', 'purple']
    
            m = 0
    
            x1 = int(self.e_x1.get())
            y1 = int(self.e_y1.get())
            x2 = int(self.e_x2.get())
            y2 = int(self.e_y2.get())
            tell = int(self.e_tell.get())
            coords = x1, y1, x2, y2
    
            for c in colors:
    
                self.w.create_arc(coords, start = 0, extent = m / c, fill = c)
                m += tell
    
                    
    
            self.e_x1.delete(0, END)
            self.e_y1.delete(0, END)
            self.e_x2.delete(0, END)
            self.e_y2.delete(0, END)
            self.e_tell.delete(0, END)
    
    
    
    if __name__ == "__main__":
    
        root = Tk()
        Window(root)
        root.mainloop()



    I means to create an color arc generator as training.... just it must be extent an remaining, based
    on the colors they called in my list..... how other the color, how bigger the extented angle yet...

    I am an newbie in do calculations for generator programs/software and later i want to do can this
    for as example world editors, model editors, etc.... so i use python to learn it about...

    So if i run my script, this is my error i get:
    Exception in Tkinter callback
    Traceback (most recent call last):
    File "C:\Python27\lib\idlelib\rpc.py", line 412, in pollresponse
    qmsg = response_queue.get(0)
    File "C:\Python27\lib\Queue.py", line 165, in get
    raise Empty
    TypeError
    If you do not know what i means..., you can help me to give an link to an good serie examples
    or books for write generated software in python, just to learn about these same like things....

    If you do know what i means, please can you correct my code so i can expriment with it ?....

    Thanks for help, Jamie....
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    667
    Rep Power
    40
    I removed the inheritance. Also removed the "extent" in the create_arc statement because you don't check for m/c is a number that will work for extent. Finally, only the last color will show as you create them all at the same coords, so one overlays the other.
    Code:
    from Tkinter import *
    
    class Window():
    
        def __init__(self, master=None):
    
            self.master = master
    
            self.init_window()
    
    
    
        def init_window(self):
    
            self.master.title('Canvas')
    
            self.e_x1 = Entry(self.master)
            self.e_y1 = Entry(self.master)
            self.e_x2 = Entry(self.master)
            self.e_y2 = Entry(self.master)
            self.e_tell = Entry(self.master)
            self.e_b = Button(self.master, text = "Create Line", command = self.Create)
    
            self.e_x1.pack(fill = X, side = TOP)
            self.e_y1.pack(fill = X, side = TOP)
            self.e_x2.pack(fill = X, side = TOP)
            self.e_y2.pack(fill = X, side = TOP)
    
            self.e_tell.pack(fill = X, side = TOP)
            self.e_b.pack(fill = X, side = TOP)
    
            self.w = Canvas(self.master, height = 512, width = 512)
            self.w.pack(side = TOP)
    
    
    
    
        def Create(self):
    
            colors = ['red', 'orange', 'yellow', 'lime', 'green', 'aqua', 'cyan', 'purple']
    
            m = 0
    
            x1 = int(self.e_x1.get())
            y1 = int(self.e_y1.get())
            x2 = int(self.e_x2.get())
            y2 = int(self.e_y2.get())
            tell = int(self.e_tell.get())
    
            coords = x1, y1, x2, y2
    
            for c in colors:
    
                self.w.create_arc(coords, start = 0, fill = c)
                m += tell
    
    
            self.e_x1.delete(0, END)
            self.e_y1.delete(0, END)
            self.e_x2.delete(0, END)
            self.e_y2.delete(0, END)
            self.e_tell.delete(0, END)
    
    
    
    if __name__ == "__main__":
        root = Tk()
        Window(root)
        root.mainloop()

IMN logo majestic logo threadwatch logo seochat tools logo