user3097470
user3097470

Reputation: 3

Positionning a canvas and a button in Tkinter

In Tkinter, how can I pack a canvas to the upper left corner and a button to the lower right corner? I tried with can.pack(side=...) and button.pack(side=....) but no luck. I want to get something like this Picture.

Upvotes: 0

Views: 1648

Answers (1)

user2555451
user2555451

Reputation:

You were close. You need to incorporate one more option: anchor.

Below is a simple script to demonstrate:

import Tkinter as tk

root = tk.Tk()

canvas = tk.Canvas(bg="red", height=100, width=100)
canvas.pack(anchor=tk.NW)

button = tk.Button(text="button")
button.pack(side=tk.RIGHT, anchor=tk.SE)

root.mainloop()

When you resize the window, notice how the canvas stays in the upper lefthand corner and the button stays in the lower righthand corner.

Upvotes: 2

Related Questions