Python Forum
[Tkinter] No menu bar in window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] No menu bar in window
#1
Hello,

Please could you help me to understand why I cannot properly run this code under mac OS :

#!/usr/bin/python
# coding: utf-8

from tkinter import Tk, PanedWindow, Label
from tkinter.filedialog import *
from tkinter.messagebox import *

def ouverture_fichier() :

    filename = askopenfilename(title="Ouvrir votre document",filetypes=[('txt files','.txt'),('all files','.*')])
    fichier = open(filename, 'r')
    content = fichier.read()
    fichier.close()

    Label(fenetre, text=content).pack(padx=10, pady=10)

def alert() :
    showinfo("alerte", "Bravo!")

fenetre = Tk()
fenetre.title("Analyse de transcriptions")
fenetre.resizable(True, False)
fenetre.geometry('600x500-100+100')

menubar = Menu(fenetre)

menufichier = Menu(menubar, tearoff=0)
menubar.add_cascade(label="Fichier", menu=menufichier)
menufichier.add_command(label="Ouvrir", command=ouverture_fichier)
menufichier.add_command(label="Editer", command=alert)
menufichier.add_separator()
menufichier.add_command(label="Quitter", command=fenetre.quit)

menuediter = Menu(menubar, tearoff=0)
menubar.add_cascade(label="Editer", menu=menuediter)
menuediter.add_command(label="Couper", command=alert)
menuediter.add_command(label="Copier", command=alert)
menuediter.add_command(label="Coller", command=alert)

menuaide = Menu(menubar, tearoff=0)
menubar.add_cascade(label="Aide", menu=menuaide)
menuaide.add_command(label="A propos", command=alert)

fenetre.config(menu=menubar)

fenetre.mainloop()

print ("Fenetre fermee")
1 / I run this code under : mac OS 10.13 / python 3.6.3 / tkinter.Tcl 8.5.18.0
As a result, the window appears without menu.
Here is the problem.

2/ I run this code under 2 other different windows os,
(one test is under windows XP / python 3.4.4 / tkinter.Tcl 8.6.1)
As a result, the window appears with menu.

Any idea please ?
Reply
#2
Does it appear on the mac menubarĀ  (!= windows menu bar) ?
Reply
#3
Yes you are right, the menu is on the mac menubar.
I didn't saw it before. Thank you.

So do you know an issue ?
Reply
#4
Maybe this helps:
https://stackoverflow.com/questions/4274...w-on-a-mac
Reply
#5
Ok thanks.
Now I'm going to look for a way to manage with both mac and windows OS.
Reply
#6
OK, keep us up to date
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 518 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  tkinter window and turtle window error 1885 3 6,730 Nov-02-2019, 12:18 PM
Last Post: 1885
  Menu bar not showing in gui window mlh 2 10,560 Sep-09-2018, 10:27 PM
Last Post: mlh
  update a variable in parent window after closing its toplevel window gray 5 9,097 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020