I used code originally by vegaseat

what's wrong with code
**
error :
Traceback (most recent call last):
File "C:/Users/Cameron/Computing Work/Year 13/F454 - Computing Project/Design/newthingnewthing.py", line 68, in <module> canvas.create_rectangle(x0, y0, x1, y1, fill="purple")
AttributeError: 'NoneType' object has no attribute 'create_rectangle'**

_______________________________________________

code:

from tkinter import *

data = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

#image size of small small crest = 121,150

widthOfSmallLogo = 121
widthOfLargeLogo = 238

def destroyMethod():
    global mainGUI
    mainGUI.destroy()


mainGUI = Tk()


widthOfScreen = mainGUI.winfo_screenwidth() #Get the width of the screen
heightOfScreen = mainGUI.winfo_screenheight() #Get the height of the screen

mainGUI.attributes('-fullscreen', True) #Remove top taskbar
mainGUI.geometry("%dx%d+0+0" % (widthOfScreen, heightOfScreen)) #Set the size of the window to full screen
mainGUI.resizable(width=FALSE, height=FALSE) #Disable resizing of window
mainGUI.configure(background = "white")
infoLabel = Label(mainGUI, text = "Please Select An Option:", font = ("Eras Light ITC", 16), foreground='purple', activebackground = "white", activeforeground = "purple",borderwidth = 0, background = "white", height = 1, width = 20).place(x = (0.6*(widthOfScreen/9)), y = ((2/3)*(heightOfScreen/10)))


# create a toplevel menu
menubar = Menu(mainGUI)
fileMenu = Menu(menubar)
fileMenu.add_command(label="Exit", command=destroyMethod)
menubar.add_cascade(label="File", menu=fileMenu)


mainGUI.config(menu=menubar)







c_width = (3*(widthOfScreen/12))
c_height = (heightOfScreen/5)
generalDivider = len(data)+1
generalOffset = (((c_width-20)/generalDivider)/(len(data)+1))
canvas = Canvas(mainGUI, width=c_width, height=c_height, bg= 'white').place(x=(4.5*(widthOfScreen/12)),y= (2*(heightOfScreen/5)))


y_stretch = 15

y_gap = 20

x_stretch = 15
x_width = 50

x_gap = 20
for count in range(0,len(data)+1, 1):

    x0 = 3+((generalOffset*(count+1))+(count*(c_width/generalDivider)))
    y0 = c_height - (data[count] * y_stretch + y_gap)
    x1 = x0+((c_width-20)/generalDivider)
    y1 = c_height - y_gap


    canvas.create_rectangle(x0, y0, x1, y1, fill="purple")

    canvas.create_text(x0+2, y0, anchor=tk.SW, text="y%")




mainGUI.mainloop() #start the event loop

Geometry managers, pack, grid, and place return None

canvas = Canvas(mainGUI, width=c_width, height=c_height, bg= 'white').place(x=(4.5*(widthOfScreen/12)),y= (2*(heightOfScreen/5)))
print canvas

Take a look at Vegas's code again and I'm sure you will find that the geometry manager is on a separate line.

canvas = Canvas(mainGUI, width=c_width, height=c_height, bg= 'white')
print canvas
print canvas.place(x=(4.5*(widthOfScreen/12)),y= (2*(heightOfScreen/5)))

Edited 3 Years Ago by woooee

Comments
Thankyou, very helpful
This question has already been answered. Start a new discussion instead.