Reputation: 35
I have some code like
from tkinter import *
root = Tk()
root.geometry("800x700+0+0")
#---------Backgroud of the main canvas-----`enter code here`-------
backGroundCanvas = Canvas(root,bg = 'white', width = 800, height = 600)
backGroundCanvas.focus_set()
backGroundCanvas.pack()
#--------------------------------------------------
#--------The other widgets out of the canvas--------
scoreLabel = Label(root, text = 'Your score is: 0', bg = 'red')
scoreLabel.place(x = 300, y = 750)
scoreLabel.pack()
root.mainloop()
But no matter how I change the parameter of the place method, the label always in the same place and can not be changed.I do not know why! Please help me , thanks a lot!
Upvotes: 0
Views: 5234
Reputation: 1571
In TKinter there is three basic Geometry manager : Grid, Pack, Place.
You should try to avoid the use of place as often as possible using instead Grid or pack ( I personally consider that only grid is a good manager, but this is only my opinion).
In your code you are setting a position to your widget using place manager, and then give the control to the pack manager. Just remove the scoreLabel.pack()
et voila!
NB : your application is 700px high, and you are trying to place your red label at 750px from the top, you're widget will be outside of the screen.
NBB : I strongly recommend the use of grid manager.
from tkinter import *
root = Tk()
root.geometry("800x700+0+0")
#---------Backgroud of the main canvas-----`enter code here`-------
backGroundCanvas = Canvas(root,bg = 'white', width = 800, height = 600)
backGroundCanvas.focus_set()
backGroundCanvas.pack()
#--------------------------------------------------
#--------The other widgets out of the canvas--------
scoreLabel = Label(root, text = 'Your score is: 0', bg = 'red')
scoreLabel.place(x = 300, y = 600)
root.mainloop()
Upvotes: 2