Menu Bars With tKinter - Python Tkinter GUI Tutorial #46

Поделиться
HTML-код
  • Опубликовано: 21 июл 2024
  • In this video I'll show you how to create Menu bars at the top of your tKinter programs.
    Menus in tKinter are incredibly easy. You just define them, configure them, then cascade them onto the screen. Each top level item you add to your menu is treated like a sub-menu.

Комментарии • 199

  • @markjocelyn5132
    @markjocelyn5132 4 года назад +5

    Thank you for demystifying Python GUI in this series of lessons. I battled getting my mind around visual basic decades ago and gave up the idea of trying anything with a GUI. This and your lessons on using databases with tkinter you have posted on RUclips has been a real pleasure to follow. You really should add these series to your academy even if you just link to the RUclips videos as this lessons are what i signed up with you for and I do feel it adds extra value and your efforts has made becoming a client of yours worth the investment.

    • @Codemycom
      @Codemycom  4 года назад

      My Codemy.com website has a tkinter course with 50+ videos. These youtube videos here on youtube that you mention are...well...here on youtube. Anyone with a codemy membership can watch them here anytime they want. The link to the playlist is in the comment section of every video.

  • @saganasimov4891
    @saganasimov4891 4 года назад +15

    Thank you very for these video tutorials, it really saves me time in searching in the internet and I really appreciate it.

    • @Codemycom
      @Codemycom  4 года назад +5

      You're very welcome!

  • @EFoxVN
    @EFoxVN Год назад

    Thanks so much John, I just LOVE your videos. Please know that your efforts are much appreciated from all over the world. Blessings

  • @Codemycom
    @Codemycom  4 года назад +1

    ▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My RUclips Channel:
    bit.ly/2UFLKgj bit.ly/2IGzvOR
    ▶️ See More At: ✅ Join My Facebook Group:
    Codemy.com bit.ly/2GFmOBz
    ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
    Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN

  • @mihaiopricescu211
    @mihaiopricescu211 4 года назад +27

    Thank you for the series of these tutorials. I discovered after I saw your video that I like to use the "tearoff" option to not have the "-------------" at the beginning of the menu. Without this, if you click on it it will open actually the menu in a new window.

    • @Codemycom
      @Codemycom  4 года назад +5

      Nice

    • @hectorgomez28
      @hectorgomez28 4 года назад +18

      file_menu = Menu(my_menu, tearoff=0)

    • @ame367
      @ame367 3 года назад +2

      @@hectorgomez28 thanks :)

    • @jorgeachar8320
      @jorgeachar8320 3 года назад +1

      I appreciate it :)

    • @Discodave676
      @Discodave676 2 года назад +1

      @@hectorgomez28 This is what we need! Thanks!

  • @rabiumuhammedeffect423
    @rabiumuhammedeffect423 2 года назад

    we will one day reference our carrier to this great man!!!. A BIG THANKS FROM THIS SIDE "JOHN". my name is Muhammed from Ghana.

  • @marisasharma1411
    @marisasharma1411 4 года назад

    Looks cool! I love your edit :)

  • @gisellgonzalezrodriguez1162
    @gisellgonzalezrodriguez1162 2 года назад

    I LOVE this channel.

  • @jesterlw
    @jesterlw 4 года назад

    Excellent video and very understandable.

  • @fvefa
    @fvefa 4 года назад

    Your videos are very helpfull and easy to understand

    • @Codemycom
      @Codemycom  4 года назад

      Thanks! Glad you like them!

  • @mryotzin
    @mryotzin 4 года назад

    great video !
    it helps me a lot !

  • @JeffBurow
    @JeffBurow 2 года назад

    Your content is awesome and has really helped me learn tkinter and python to a degree of some effectiveness. I am working on a small GUI. It is being displayed on a 7" HDMI screen connected to a Pi4. To maximize my real estate, I would like to slide/collapse the menu bar out of the way and hide it. I have not been able to find anything anywhere on how to do this without manually creating an entire menubar. Is this possible? If not, I will use tkinter's menu system rather than build it from scratch for this project.

    • @Codemycom
      @Codemycom  2 года назад +1

      No, there's no built in thing for that...you'll have to hack it together yourself

  • @poparab
    @poparab Год назад

    small Question:
    Can we read an Array from Javascript generated (in the Memory) (RAM) and read with python. Python was the wonder magic all inkl. Language. So I think this can gone work.

  • @terfer9128
    @terfer9128 4 года назад +1

    I was waiting for this to upgrade my simple calculator and I really wanna add a lot of thing but i don’t already know what to do please add a vid named upgrating the calculator please answer me !

  • @RajuSinghp3ntester
    @RajuSinghp3ntester 3 года назад

    @codemy Icon doesn't work when we build the app with pyinstaller and ship to another system

  • @binkyslife
    @binkyslife Год назад

    Thank you!

  • @shrinidhimohandeshpande656
    @shrinidhimohandeshpande656 3 года назад +1

    Thank you for the very informative tutorial.
    Can you please educate me on changing the background color of the title / menu bar. ?
    Thank-you.

  • @RyanDanielG
    @RyanDanielG 2 года назад

    feed the algorithm! great vid!

  • @heshankumarasinghe3159
    @heshankumarasinghe3159 3 года назад

    Thank you.... This video is helpful.....

    • @Codemycom
      @Codemycom  3 года назад +1

      Glad it was helpful!

  • @summaalchemica364
    @summaalchemica364 Год назад

    awesome, thanks!

  • @stevecavell1943
    @stevecavell1943 3 года назад +1

    Love your videos. I was following this tutorial and could not work out why it was "not working" for ages. Turns out if you are on a Mac it IS working but the menu bar is placed at the top of the screen not in the working window!

  • @kutup1763
    @kutup1763 Год назад +1

    How can I delete the sentences after I select my options?
    I mean how I delete Friday text after I select Monday

  • @abteyeb7969
    @abteyeb7969 2 года назад

    Thank you very for all

    • @Codemycom
      @Codemycom  2 года назад

      Thanks for watching!

  • @namanallawadhi7397
    @namanallawadhi7397 2 года назад

    thank you Heisenberg :)

  • @howimetstarwars356
    @howimetstarwars356 3 года назад

    Hello tahnk u ! I am asking than. How can i use link with menu bar ?

  • @davoodbarzegari4080
    @davoodbarzegari4080 10 месяцев назад

    thank you, sir.
    what is the software you are using to write the code? I use IDLE but it is not so user friendly.

    • @Codemycom
      @Codemycom  10 месяцев назад

      Sublime Text and the Git Bash terminal...never use IDLE for anything :-p

  • @madaniselilih331
    @madaniselilih331 Год назад

    Thank you for this great explanation, but I have a question how to make the menu from right to left for Arabic.

  • @sayedbalal541
    @sayedbalal541 3 года назад

    how to change the menu size and height?

  • @judeleon8485
    @judeleon8485 4 года назад

    Thanks a million for this video. However, is it possible to have menu bar inside a frame or notebook, instead of having it in the root window? If it is possible, can you please let us know how.

    • @Codemycom
      @Codemycom  4 года назад

      Not sure what you mean, but you can have drop down menus in those places.

    • @judeleon8485
      @judeleon8485 4 года назад

      Well, I am not talking about dropdown as in optionmenu. I mean creating menu widget in a frame as file_menu = menu(frame). In your video you placed the menu bar on the root window as file_menu=menu(root). I tried it by replacing the root with a frame widget and got an error

  • @jokywood1489
    @jokywood1489 Месяц назад

    sir we used functions like main_menu.add_cascade(label = 'some text', menu = file_manu)
    i want to know the source code of these functions that how the functions like add_cascade(), Menu() etc are developed.
    these functions are inbuilt and i want to know how these functions have been created.
    Please sir explain, pleas sir

  • @eduardofloresramones72
    @eduardofloresramones72 4 года назад

    Very helpful :)

  • @Zhisaoka
    @Zhisaoka 3 года назад

    I am trying to make a menu that opens a python file, I am quite into the video and my code will not work, its almost the same but it still won't work. It just will show a blank gui with a title, Code:
    Edit: Nvm on mac it just looks diffrent
    from tkinter import *
    root = Tk()
    root.title("Techno Play Menu")
    root.geometry("400x400")
    my_menu = Menu(root)
    root.config(menu=my_menu)
    def command():
    pass
    file_menu = Menu(my_menu)
    my_menu.add_cascade(label="File", menu=file_menu)
    file_menu.add_command(label="New...", command=command)
    file_menu.add_command(label="Exit", command=root.quit)
    root.mainloop()

  • @karthikeeyan1653
    @karthikeeyan1653 3 года назад

    Can u tell how to increse the font size of words in the menu bar like file,edit..

  • @user-fd4sk8ev4d
    @user-fd4sk8ev4d 11 месяцев назад +1

    Hey, I just have a question about python Tkinter. If I made a button in Tkinter where text appears on the screen when the button was clicked how do I make it so that when I run my code and press the button the text stays there when I close the program and re run it?

    • @Codemycom
      @Codemycom  11 месяцев назад +1

      You don't, unless you save that state to a database or something...or a text file or something.

    • @user-fd4sk8ev4d
      @user-fd4sk8ev4d 11 месяцев назад

      @@Codemycom Okay thank you, do you have a video on how to save it to a text file or database?

    • @Codemycom
      @Codemycom  11 месяцев назад +1

      @@user-fd4sk8ev4d Sure, lots...check the playlist

  • @AnujKumar-xn5tg
    @AnujKumar-xn5tg 3 года назад +2

    Sir, can we remove that dotted line? when we click that it separate out of the Menu
    Its look like a separator above New and Edit.

  • @lukemanabdelrahim3740
    @lukemanabdelrahim3740 2 года назад

    Thank you so much

  • @benjaminnicholls5405
    @benjaminnicholls5405 4 года назад

    Should it work if I place the menu inside of a frame?

  • @sameehazahid466
    @sameehazahid466 Год назад +1

    mine says 'unknown option -Label'
    Why?

  • @pverprogramz641
    @pverprogramz641 4 года назад

    sir, is it possible to delete a menu item when clicking a button ??
    Like menu.delete_cascade() or something like that

    • @Codemycom
      @Codemycom  4 года назад

      I'm sure there is, but I don't think I've ever tried it :-p

    • @pverprogramz641
      @pverprogramz641 4 года назад

      @@Codemycom I think you should try that . 😜

  • @lilytucker2464
    @lilytucker2464 Год назад

    Hello, thanks so much for your tutorials - but, I have a question, why do some teachers, such as yourself, start with "root = Tk()" and others start with "main_window = Tk()"? What is the difference and can I add the "root" at the beginning of my code or do I have to redo all of my work? Please and thanks...

    • @Codemycom
      @Codemycom  Год назад

      They're both the same, you can call a variable anything you want. root is short and universal. but you could call it happy_bob if you want, it doesn't matter, you just have to use that throughout the entire app.

    • @lilytucker2464
      @lilytucker2464 Год назад

      @@Codemycom Awesome! Thanks again!! I guess I thought it a command rather than a variable, so I'm glad to understand it now. Maybe it was mentioned somewhere along the line and I missed it, so I appreciate you explaining it. 😊

  • @ClusterSeries
    @ClusterSeries 4 года назад +1

    Sir, Can you please make a video on pyperclip module ?.

    • @Codemycom
      @Codemycom  4 года назад

      Sorry, I'm not familiar with that

  • @tylergamer5276
    @tylergamer5276 2 года назад

    I got question, how do u remove the fact if u click on the "-------------" at the top of the drop box of a menu, it pops that menu out, how do u stop this from happening??

    • @Codemycom
      @Codemycom  2 года назад

      You can remove that bar...I have videos on that in the playlist somewhere

    • @MelodyandInspiration
      @MelodyandInspiration Год назад

      file_menu = Menu(my_menu, tearoff=False)

  • @hamadc.2966
    @hamadc.2966 4 года назад +1

    Hi! Thank you sooo much for these tutorials
    I've copied your code exactly but when its time to compile, there's an error:
    _tkinter.TclError: unknown option "-menu"
    this is on the root.config(menu = root)
    How do I fix this???

    • @Codemycom
      @Codemycom  4 года назад +2

      Every time someone says that they copied the code exactly but there was an error...they didn't copy the code exactly. Check for typos.

    • @jesterlw
      @jesterlw 4 года назад +1

      The error you got was from capitalizing the L in label.

    • @vivek254258
      @vivek254258 4 года назад +1

      @@jesterlw I got the same problem with my program,thanks for showing me the solution

    • @ferdindonbosco246
      @ferdindonbosco246 4 года назад

      @@Codemycom Lol...seems like you get that a lot!! I can sense the frustration 😉

    • @Codemycom
      @Codemycom  4 года назад

      @@ferdindonbosco246 You have no idea LOL

  • @kamiftc5598
    @kamiftc5598 Год назад

    what do i need to put for root.iconbitmap, just asking and have no clue

    • @Codemycom
      @Codemycom  Год назад

      That's the icon that goes on the top menu bar of the app

  • @navneetyadav8869
    @navneetyadav8869 4 года назад +1

    Sir could u send the code in the description,I was having problem with the program ,so I'll be able to copy paste the code

    • @Codemycom
      @Codemycom  4 года назад +3

      My code is here: github.com/flatplanet/Intro-To-TKinter-RUclips-Course
      But you shouldn't need to copy and paste code. Rewatch the video and work it out man.

    • @navneetyadav8869
      @navneetyadav8869 3 года назад

      @@Codemycom hmm just will check out the difference

  • @MSTSLive
    @MSTSLive 5 месяцев назад +1

    sir can you please tell me how i can also add it in customtkinter

    • @Codemycom
      @Codemycom  5 месяцев назад

      I have an entire customtkinter playlist over on the tkinter.com RUclips channel.

  • @rishavmasih9450
    @rishavmasih9450 3 года назад +2

    Lmao John at 0:00

    • @NEXC
      @NEXC 3 года назад

      Excited for teach

  • @MickForjay
    @MickForjay 6 месяцев назад

    how do you get rid of the dashed lines that appear above the menu items?

    • @Codemycom
      @Codemycom  6 месяцев назад

      tearoff=0 (or maybe 1 I can;t recall)

    • @MickForjay
      @MickForjay 6 месяцев назад

      @@Codemycom thank you

    • @Codemycom
      @Codemycom  6 месяцев назад

      welcome@@MickForjay

  • @cpremix859
    @cpremix859 3 года назад

    Awesome

  • @TaxManianDevil
    @TaxManianDevil Год назад

    Does this work the same with customtkinter?

    • @Codemycom
      @Codemycom  Год назад

      nothing works quite the same with customtkinter

  • @jtwnow4342
    @jtwnow4342 3 года назад

    When add menu bar it will not open middle in the screen...please help me

    • @Codemycom
      @Codemycom  3 года назад +1

      check your code for typos

  • @awhlox9099
    @awhlox9099 4 года назад

    I can already code in python what else should I learn to code ? What’s do you recommend to create things

    • @Codemycom
      @Codemycom  4 года назад

      Depends entirely on the type of things you want to create...

    • @awhlox9099
      @awhlox9099 4 года назад

      Codemy.com what’s the best language to learn overall instead of python

    • @Codemycom
      @Codemycom  4 года назад

      @@awhlox9099 Depends entirely on what you're trying to do...best for what? Building websites? Designing Games? Doing Big Data? Running Server? See what I mean?

    • @awhlox9099
      @awhlox9099 4 года назад

      Codemy.com yes. But what language should I learn next I’ve learned python and now what other languages are fun

    • @Codemycom
      @Codemycom  4 года назад

      @@awhlox9099 I've already answered you...it depends. period. What do you want to do? Build websites? Build games? Do big data? It depends dude. I can't explain it any other way. lol What language you learn next will be determined wholly by what you want to do with it. And anyway, they're all fun...

  • @supersonic6734
    @supersonic6734 3 года назад

    Can I cascade a Menu to a label frame instead of root?

    • @Codemycom
      @Codemycom  3 года назад

      Try it and see

    • @supersonic6734
      @supersonic6734 3 года назад

      @@Codemycom I did try before I posted the comment. I did try it again as you said. First it did not work. Labelframe.config(menu=my_menu) did not work. But root.config(menu=my_menu) worked.

  • @dragoneater2008_
    @dragoneater2008_ 3 года назад

    Can I replace the menu with a button? If so how?

    • @Codemycom
      @Codemycom  3 года назад

      Sure, in the normal way you would use any button.

  • @sharfer374
    @sharfer374 3 года назад

    Thanks

  • @Spasmaticus
    @Spasmaticus 4 года назад

    Do I have to use "root"? I'm currently using "window" instead and i'm getting some errors.
    "my_menu = Menu(window)
    NameError: name 'Menu' is not defined"
    This is my code:
    import tkinter as tk
    import tkinter.messagebox
    window = tk.Tk()
    [....]
    def testFunc():
    pass
    # The menu
    my_menu = Menu(window)
    window.config(menu=my_menu)
    # The menu items
    file_menu = tk.Menu(my_menu)
    my_menu.add_cascade(Label="File", menu=file_menu)
    file_menu.add_command(Label="New", command=testFunc)
    file_meny.add_command(Label="Exit", command=testFunc)

    • @Codemycom
      @Codemycom  4 года назад +1

      If you use window, you would use window, not root...but hey, if you don't know what you're doing...which you don't seem to...why not just follow along and do it like I do in the video and save yourself some aggravation? Did you forget to window = Tk() at the top of your program?

    • @ame367
      @ame367 3 года назад

      are you missing a mainloop for your mini instance of tkinter?

  • @ibrahimkhayat8046
    @ibrahimkhayat8046 3 года назад

    How can I add this menu in a class?

    • @Codemycom
      @Codemycom  3 года назад

      In the same way you add anything in a class with tkinter

  • @gamepunk7963
    @gamepunk7963 3 года назад

    Umm there’s something wrong with pycharm it does not recognize label but
    Tkinter recognized Label before...,why is it doing that

    • @Codemycom
      @Codemycom  3 года назад

      No idea, I would never use Pycharm, it's terrible

    • @RyanDanielG
      @RyanDanielG 2 года назад

      for future questioners: lower case 'label'

  • @TunodeGaming
    @TunodeGaming 3 года назад

    How to Chance cascade's font. :?

    • @Codemycom
      @Codemycom  3 года назад +1

      Not sure if you can

    • @TunodeGaming
      @TunodeGaming 3 года назад

      @@Codemycom OK, thx anyway!!

  • @Abdulaziz-e-2030
    @Abdulaziz-e-2030 3 года назад

    hello teacher I did same you write but the eror is (( self.tk.call((self._w, 'add', itemType) +
    _tkinter.TclError: unknown option "-Label")). iam using Mac the same code I did is same what you did could you help pls

    • @Abdulaziz-e-2030
      @Abdulaziz-e-2030 3 года назад

      your code = my code that is why I could not understand whats wrong

    • @Codemycom
      @Codemycom  3 года назад

      No, my code does not equal your code...you have a typo someone. If they equaled, you wouldn't have an error.

    • @Abdulaziz-e-2030
      @Abdulaziz-e-2030 3 года назад

      @@Codemycom if you can help😊😁
      I would to send all the code if you can check
      I wached all the previous 45 lessons i dont want to jump th 46th

    • @Codemycom
      @Codemycom  3 года назад

      @@Abdulaziz-e-2030 No sorry, but the error is telling you what the problem is. You've used Label incorrectly somewhere.

    • @Abdulaziz-e-2030
      @Abdulaziz-e-2030 3 года назад

      @@Codemycom teacher pls see my code on twitter I am sure no mistakes with (Label).
      twitter.com/abdoh69424/status/1339420201574690818?s=21

  • @terfer9128
    @terfer9128 4 года назад

    Which EDI you are using ?

    • @Codemycom
      @Codemycom  4 года назад

      EDI?

    • @terfer9128
      @terfer9128 4 года назад

      Compeleter ?

    • @Codemycom
      @Codemycom  4 года назад

      @@terfer9128 yeah I don't know what you're talking about...I'm using sublime text

    • @terfer9128
      @terfer9128 4 года назад

      Ok i have a problem . After i have done my simple calculator with ‘ thonny’ i decided to move for pycharm and i opened the simple calculator file and there is a trouble in running why ?

    • @Codemycom
      @Codemycom  4 года назад +1

      @@terfer9128 Because pycharm sucks...why not just use Sublime Text like I do in the video? It's easy. It's free.

  • @NEXC
    @NEXC 3 года назад +1

    To everyone having errors please check your spelling for 'label'

    • @Codemycom
      @Codemycom  3 года назад +1

      it's usually a typo yes

    • @gacem213
      @gacem213 2 года назад +1

      ur comment helped thanks a lot, I thought the l was capital because of the font

    • @NEXC
      @NEXC 2 года назад

      @@gacem213 :D

  • @ishvargh2014
    @ishvargh2014 4 года назад

    I cant read that with my phone.

    • @Codemycom
      @Codemycom  4 года назад

      Everyone else can...zoom in

  • @Wuottfac
    @Wuottfac 3 года назад

    unknown option "-Label" why?

    • @Codemycom
      @Codemycom  3 года назад

      what did you do in your code?

    • @Wuottfac
      @Wuottfac 3 года назад

      @@Codemycom i just solved my problem , thank you

    • @Codemycom
      @Codemycom  3 года назад

      @@Wuottfac awesome

    • @officialteamnight2807
      @officialteamnight2807 3 года назад

      is label not Label

    • @Codemycom
      @Codemycom  Год назад

      @@jadenlin3724 glad to hear it!

  • @celiafernandes9084
    @celiafernandes9084 4 года назад

    It is not working sir,showing error

    • @Codemycom
      @Codemycom  4 года назад

      What's the error say? They tell you what to do...

  • @Hh12358
    @Hh12358 4 года назад

    Hi John, following is the code I tried after looking at your amazing tutorial but I don't know why it's not working.It would be amazing if you help me out.
    from tkinter import *
    root = Tk()
    root.title("HP SIMPLE FINANCE")
    w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    root.geometry("%dx%d+0+0" % (w, h))
    def donothing():
    pass
    menubar = Menu(root)
    root.config(menu=menubar)
    filemenu = Menu(menubar)
    menubar.add_cascade(Label="File", Menu=filemenu)
    filemenu.add_command(Label="Open Portfolio file", command=donothing)
    filemenu.add_command(Label="Reports", command=donothing)
    filemenu.add_command(Label="New Portfolio", command=donothing)
    filemenu.add_command(Label="Restore from backup", command=donothing)
    filemenu.add_command(Label="Exit", command=root.quit)
    root.mainloop()
    The error shows as follows:
    Traceback (most recent call last):
    File "F:/Finance software/Main window.py", line 28, in
    menubar.add_cascade(Label="File", Menu=filemenu)
    File "C:\Users\harshparmar\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 3289, in add_cascade
    self.add('cascade', cnf or kw)
    File "C:\Users\harshparmar\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 3284, in add
    self.tk.call((self._w, 'add', itemType) +
    _tkinter.TclError: unknown option "-Label"
    Process finished with exit code 1

    • @Codemycom
      @Codemycom  4 года назад +2

      All those Labels need to be lowercase label

    • @Hh12358
      @Hh12358 4 года назад

      @@Codemycom Hi John, I corrected it still same error, except last error changed to this:
      self.tk.call((self._w, 'add', itemType) +
      _tkinter.TclError: unknown option "-Menu"

    • @garrybeck216
      @garrybeck216 4 года назад +1

      @@Hh12358 Menu (within brackets) needs to be in lower case as it is a key word and not a class.

    • @ame367
      @ame367 3 года назад

      in menubar.add_cascade(Label="File", Menu=filemenu) change that "Menu" to "menu"

    • @aymaneam
      @aymaneam 2 года назад

      Same problem

  • @gameknight_10
    @gameknight_10 Год назад

    Not Working

    • @Codemycom
      @Codemycom  Год назад

      Then you did it wrong. Watch the video and try again.

  • @atakheli3608
    @atakheli3608 3 года назад +1

    If root.quit does not work, use root.destroy

  • @KarimKarim-kk5mn
    @KarimKarim-kk5mn 3 года назад

    Cir, please programme password

  • @sarangpratham6965
    @sarangpratham6965 4 года назад

    Hii

  • @AEfsaenti
    @AEfsaenti Год назад

    Many thanks to GOOGLE for automatic translation