0

I'm using python 3 and tkinter module for creating a GUI. I need to create a menu bar and align items on it from right to left (I want to use that with Persian language so I need to align my menu items from right to left), now I have used from this code but it didn't aligned file and edit items from right to left and they still align from left to right in the menubar. How can I deal with it?

from tkinter import *
from tkinter import ttk

root = Tk()
root.title('Create Menu bar and items')
root.geometry('300x300+100+50')
root.option_add('*tearOff', False)
menubar = Menu(root)
root.config(menu = menubar)
file = Menu(menubar)
edit = Menu(menubar)
menubar.add_cascade(menu = file, label = 'فایل',compound = RIGHT)
menubar.add_cascade(menu = edit, label = 'ویرایش',compound = RIGHT)
Mehdi Soltani
  • 163
  • 3
  • 13

2 Answers2

1

Use a simple trick, create a blank menu between the itens ;-)

blankmenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label="".ljust(130), menu=blankmenu)
GedeAl
  • 11
  • 3
  • Do you think there would be a way to read the window width, and input that as an integer? E.G `(label="".ljust(int(window-width))` – level42 Jun 14 '17 at 16:45
0

I don't believe you can do what you want. I've not used Tkinter with a right-to-left language so I can't say for sure, but you're limited to what the OS supports for menubars. Tkinter gives you no control over where items are placed on a menubar, other than the relative order.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685