[Tutor] Tkinter canvas on frame
Phil
phillor9 at gmail.com
Sat Feb 26 23:55:43 EST 2022
This is part of a project I was working on a couple of months ago and I
didn't notice that there is a problem until today when I added some colours.
The question is, how can I site the canvas on the frame so that the blue
frame surrounds the canvas? Without the canvas the whole frame is blue.
I suspect that it's to do with the pack manager.
import tkinter as tk
class Root(tk.Tk):
def __init__(self):
super().__init__()
self.title("Canvas Template")
self.geometry("400x300")
self.frame = tk.Frame(background='cornflowerblue')
self.frame.pack(fill=tk.BOTH, expand=1)
canvas = tk.Canvas(self, relief='flat', background='lightgrey',
width=200, height=200)
canvas.pack(side=tk.TOP, anchor='nw', padx=10, pady=10)
quit_button = tk.Button(self, text="Quit", command=self.quit)
quit_button.pack(side=tk.BOTTOM, anchor='se', padx=10, pady=10)
if __name__ == "__main__":
root = Root()
root.mainloop()
--
Regards,
Phil
More information about the Tutor
mailing list