Mirac7
Mirac7

Reputation: 1646

Both image and label in menu

I am trying to add icons to commands in tkinter menu bar. I used this code to add images:

file_menu.add_command(label="Create new project", image=icons["new"], command=new_project)

but it resulted in this:

Result image

How do I show both an image and a label?

Upvotes: 3

Views: 1296

Answers (1)

Bhargav Rao
Bhargav Rao

Reputation: 52101

The menu or any label takes in an argument called compound

file_menu.add_command(label="Create new project", image=icons["new"],compound = LEFT, command=new_project)

here LEFT is from tkinter package and is for alignment. It is used to indicate as to which side the image has to be placed.

NOTE: If you have used import tkinter then you will have to write compound = tkinter.LEFT

Upvotes: 4

Related Questions