4

The following code results in in a menubar with cascading menus that are anchored at the right instead of the left for unknown reason.

import tkinter as tk

class Menubar(tk.Menu):
    def __init__(self, parent, *args, **kwargs):
        tk.Menu.__init__(self, parent, *args, **kwargs)

        filemenu = tk.Menu(self, tearoff=False)
        self.add_cascade(label="File",underline=0, menu=filemenu)
        filemenu.add_command(label="Exit", underline=0, command=None)

        testmenu = tk.Menu(self, tearoff=False)
        self.add_cascade(label="Test",underline=0, menu=testmenu)
        testmenu.add_command(label="First option", underline=0, command=None)


class MainApplication(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)

        menubar = Menubar(parent)
        parent.config(menu=menubar)

if __name__ == "__main__":
    root = tk.Tk()
    MainApplication(root).pack(side="top", fill="both", expand=True)
    root.mainloop()
sbdev01
  • 81
  • 3
  • They appear left-justified to me. What OS are you running this on? What do other menus on other applications look like, are they right-justified too? – Bryan Oakley Nov 12 '15 at 16:00
  • Tk menus appear on the left of the cursor if you launch them such that they would draw over the right edge of the screen. Are you near an edge? Looks normal when I tested on Windows, except right over on the right of my screen. – patthoyts Nov 12 '15 at 16:08

1 Answers1

4

I was able to fix the problem. I first only noticed the problem within my own application, while others seemed to work normally. After trying a few other applications it seemed the problem wasn't limited to my own. I guess the ones I tried first didn't have the problem, because they likely used a different widget toolkit. The problem is caused by Windows (8.1), which automagically switched some settings for tablets (I have a semi-tablet: Lenovo Thinkpad Yoga).

The problem was solved by running the following command (press windows key + R to run commands)

shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E}

This will get you to the "Tablet PC Settings". In the "Other"-tab you have to make sure "Left-handed" is selected. This will change the appearance of the menus to normal.

sbdev01
  • 81
  • 3