Add Scrollbars to List Boxes - Python Tkinter GUI Tutorial #62

Поделиться
HTML-код
  • Опубликовано: 15 окт 2024

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

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

    ▶️ 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

  • @noobmeky
    @noobmeky 4 года назад +7

    Really appreciate your videos man!!!
    The pace of these tutorials are great and the tips on the nuances of the tkinter library has saved me so much time in writing code in my own project.

  • @khaihoang7420
    @khaihoang7420 4 года назад +8

    I have learn a ton from your tutorial. I found that your videos are a lot better than docs. I hope you will consider doing videos on pygame.

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

      Thanks :-) I might..

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

    Hey! I just wanted to say HUGE THANKS! you are doing great work, and if ever you feel like stopping, Dont. It's because of people like you that people like us thrive, and learn. God Bless You!

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

      I appreciate that!

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

    Your tutorials are awesome. I always search for helpful videos on your channel. I love them. Please make more videos so that more people can smash the like button.

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

      Thanks! I make more every day, there are over 200 tkinter videos in this playlist alone :-)

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

    very nice, i updated the code so all the buttons work since it was not doing what it was supposed to. I took your code and redid the select_all and the select since it was not doing it's thing as your described it. Your video helped me get started and thinking on how to solve the problem so it works.
    from tkinter import *
    root = Tk()
    root.title('List Boxes')
    root.geometry("400x600")
    #Create frame and scrollbar
    my_frame = Frame(root)
    my_scrollbar = Scrollbar(my_frame, orient=VERTICAL)
    #Listbox!
    #Single, Browse, Multiple, Extended can set it for, when deleting making a list
    my_listbox = Listbox(my_frame, width = 50, yscrollcommand=my_scrollbar.set, selectmode=MULTIPLE)
    #configure scrollbar
    my_scrollbar.config(command=my_listbox.yview)
    my_scrollbar.pack(side=RIGHT, fill=Y)
    my_frame.pack()
    my_listbox.pack(pady=15)
    #Add item to listbox
    my_listbox.insert(END, "This is an item")
    my_listbox.insert(END, "Second Item!")
    #Add list of items
    my_list = ["One", "Two", "Three", "One", "Two", "Three", "One", "Two", "Three", "One", "Two", "Three", "One", "Two", "Three"]
    for item in my_list:
    my_listbox.insert(END, item)
    def delete():
    for item in reversed(my_listbox.curselection()): # deletes last item first
    my_listbox.delete(item)
    my_label.config(text='')
    def select():#create a new variable and string together things on seperate lines
    result = ''
    for item in (my_listbox.curselection()):
    result = result + str(my_listbox.get(item)) + '
    '
    my_label.config(text=result)
    def delete_all():
    my_listbox.delete(0, END) #range of what to delete
    def select_all():
    my_listbox.select_set(0, END)
    def delete_multiple(): #loops through and the list changes need to use reverse, starts at the beginning deletes the 0th item, then the next item is 1 and the list is changed
    for item in reversed(my_listbox.curselection()): #deletes last item first
    my_listbox.delete(item)
    my_label.config(text='')
    global my_label
    my_label = Label(root, text='')
    my_label.pack(pady=5)
    my_button = Button(root, text="Delete", command=delete)
    my_button.pack(pady=10)
    my_button2 = Button(root, text="Select", command=select)
    my_button2.pack(pady=10)
    my_button3 = Button(root, text="Delete All", command=delete_all)
    my_button3.pack(pady=10)
    my_button4 = Button(root, text="Select All", command=select_all)
    my_button4.pack(pady=10)
    my_button5 = Button(root, text="Delete Multiple", command=delete_multiple)
    my_button5.pack(pady=10)
    root.mainloop()

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

      now I am trying to figure out how to make an undo button

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

    In the previous video you mention that you have seen it where people need to use "end" and in other cases you don't. Not sure if this is what you were talking about, but it seems to be because of the imports.
    If you import Tkinter by itself like "import tkinter as tk" then to use things like END or ANCHOR you need to include tk.END. However, the option "end" works either way.

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

    Wonderful sir ...great teaching.... continue...

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

    Thanks for such a great tutorial!, You deserve all the best!

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

    Thanks for the great tutorial but I want to ask you that you accept Paytm or not because I want to take your subscription but it only accept paypal and credit card I don't have both...do you accept debit cards or paytm?

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

      I accept major credit cards (or their debit cards, ie MC, Visa etc) and paypal.

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

      @@Codemycom thanks a lot

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

    Hi there, really appreciate your content. I had a quick question;
    I'm noticing that when I create the scrollbar (used exact same code in ur vid), I see the scrollbar, but I don't see the gray "rectangle" to actually scroll down through the listbox. All I see is just designated space for the scrollbar with arrows up, down.
    really wish I could send a pic , but yt comments don't support that
    Keep up it with the channel !

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

      Not sure what you mean...but 100% of the time when people tell me they use the exact code I used and it turned out differently...they DIDN'T use the exact same code I did...they made a typo or changed something a little bit, usually accidentally without noticing it.

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

    Me again, I'm curious if you have a tutorial video explaining how to add both Vertical AND Horizontal scrollbars to a listbox frame like you showed in this video using the same frame or do you have to create 2 seprate frames? Thanks again for all the kick ass videos!
    EDIT:
    I did a bit of tinkering (trial and error) and I came up with this based off this video. It works probably not the best method, but I got it to work.
    CODE:
    list_frame = Frame(root, background="Cyan")
    scrollbar = Scrollbar(list_frame, orient=VERTICAL)
    scrollbarh = Scrollbar(list_frame, orient=HORIZONTAL)
    listbox = Listbox(list_frame, background="Cyan", width=20, yscrollcommand=scrollbar.set, xscrollcommand=scrollbar.set)
    scrollbar.config(command=listbox.yview)
    scrollbar.pack(side=RIGHT, fill=Y)
    scrollbarh.config(command=listbox.xview)
    scrollbarh.pack(side=BOTTOM, fill=X)
    list_frame.pack()
    LIKE I SAID B4, THANK YOU!

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

    Great series. Do you have a video on dependent drop down list boxes? For instance, if drop down list box #1 contains states, I want to create a second drop down box (#2) that contains the counties of each respective state. Say if I clicked on Colorado in the first box, then I would want to be able to click on a list of counties in Colorado in the second box. Been cruising your channel and the i-net for info on this; surprising, the topic is somewhat hard to find. Cheers

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

      No, but that's a great idea for a video.

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

    Just wondering if I am using grid system to position all the widgets, How should I position the scrollbar right next to my text box. I always have some space between the text box and the scrollbar. Thanks

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

    I am using Tkinter for the GUI of a chat application. At the moment, there is a text box, a send button, and a list of all the text. The only problem I am having is that when I run the Tkinter root.mainloop(), I can't run anything else. The loop runs until the program is closed. This prevents me from running the code that reads and sends chat messages to and from the server. How would I be able to run both the main loop and the code that sends and receives the messages at the same time?

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

      No, that's not what's happening. main loop always runs, it doesn't interfere with running anything else.. You have some other problem, likely with your code...

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

      @@Codemycom My code has been working just fine other than what is happening. The problem is that any code after root.mainloop() will not get run until you click on the x to close the Tkinter window. The Tkinter loop will run until you close the window, so I need a way to run 2 loops at once because my code is a loop as well as the Tkinter GUI loop.

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

      Could I please get some help?

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

      @@PKCubed uh, that's why root.mainloop() always goes at the end of your program. Don't put anything after it.

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

      @@Codemycom Then how am I supposed to run the internal code for the chat?

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

    Do I need two frames, if I want to place a scrollbar into a frame ? Or it is better to use 2 frames & 1 canvas instead ?

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

      never mind. it seems that can't added scrollbar directly to a frame

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

      yes you can put a scrollbar in a frame

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

    Hi,
    Thank you so much for your videos.
    I have one question,
    How can i add scroll bar to the whole root i.e.( Entire widow ) ?

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

      Might do a video on that one day

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

    Hello! Your video helps me so much! I have one question. How can I configure the shape of the scrollbar? I already used relief option, but nothing changed. And is it possible to use the image on scrollbar?

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

      I'm not sure you can really easily modify it.

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

    It's really a greate job,thank you very much,i fix the problem of scrollbar

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

    Thank..good job...merci

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

    @Codemy.com i've used grid instead of pack but for my_scrollbar.pack(side=RIGHT,fill=Y) if i use grid its giving me error can u please help me??

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

    i saw 15 of your vids today :D

  • @АзаматТулкинов-з1ъ
    @АзаматТулкинов-з1ъ 3 года назад

    i reckon you should firstly have used sorted, after reversed function cause we don't know how user will choose items in listbox

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

    I have a question. I know how to add vertical scrollbar in Listbox and also how to add horizontal one. I also know how to add vertical scrollbar to Text widget (as in ScrolledText widget). But I don't know how to add horizontal bar in Text widget (because whenever I type text more than the whole line in Text widget, it inserts text into newline ("
    ")). Do you know how to make rest of the text go in one line only until I don't press Enter key?

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

    Thank you very much You are the best! I'll nenver forget you

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

    Hello, I have a question. For example I learn tkinter pretty well and already write own app. Where I can publish my app?

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

      Publish? There is no app store for these apps. You can build a website and sell it there, or give it away or whatever.

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

    Dear Sir, could you please explain how to add a scrollbar into a optionmenu, so I wonder how to make a compact visualisation of a list which has a scrollbar as it is too long, but in a way that the user sees one item at the time and he can scroll up and down or in a way that the window with the scrolling enlarges only if the user clicks on that option. Many thanks in advance

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

    How do I use .grid with the scrollbar because it give error when you do .grid(side=RIGHT, fill=Y)?

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

      Use .grid() in the same way you always use it. It's no different just because you're using it with a scrollbar...

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

      @@Codemycom When I do that the scrollbar doesn't size, so it doesn't work

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

    I got this error:
    AttributeError: 'NoneType' object has no attribute 'yview'.
    The error/bug comes to line 17, where my_scrollbar.config(command=my_listbox.yview) is there.
    If anyone answer this, I would appreciate it :)

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

      PS: I also put yscrollcommmand to the List box, if you wonder.

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

    Can I control the entire frame with widget in it usuing scrollbars? Apart from just lists?

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

    I got my select and delete to work, but once I switched my mode to multiple it seems like ANCHOR is no longer valid. What should I do in this case? It appears that only the multiple selects and deletes work now.

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

      Sorry, I can't know what's going on with your code in order to tell you what to do...

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

      @Drew Clark If I understood correctly, you want to change the selectmode attribute to one and the same selectbox.
      If so, maybe this will help.
      from tkinter import *
      root = Tk()
      root.title("Codemy.com")
      root.geometry("400x700")
      def delete():
      my_listbox.delete(ANCHOR)
      my_label.config(text="")
      def select():
      my_label.config(text=my_listbox.get(ANCHOR))
      def select_all():
      result = ""
      for item in my_listbox.curselection():
      result = result + str(my_listbox.get(item)) + "
      "
      my_label.config(text=result)
      def delete_multiple():
      for item in reversed(my_listbox.curselection()):
      my_listbox.delete(item)
      my_label.config(text="")
      def select_single():
      my_listbox["selectmode"] = SINGLE
      my_button["state"] = NORMAL
      my_button_1["state"] = NORMAL
      my_button_3["state"] = DISABLED
      my_button_4["state"] = DISABLED
      button_single["bg"] = "red"
      button_multiple["bg"] = "white"
      def select_multiple():
      my_listbox["selectmode"] = MULTIPLE
      my_button["state"] = DISABLED
      my_button_1["state"] = DISABLED
      my_button_3["state"] = NORMAL
      my_button_4["state"] = NORMAL
      button_single["bg"] = "white"
      button_multiple["bg"] = "red"
      # Create frame and scrollbar
      my_frame = Frame(root)
      my_scrollbar = Scrollbar(my_frame, orient=VERTICAL)
      button_single = Button(root, text="Single Mode", command=select_single)
      button_single.pack(pady=10)
      button_multiple = Button(root, text="Miltiple Mode", command=select_multiple)
      button_multiple.pack(pady=10)
      # Listbox
      my_listbox = Listbox(my_frame, width=50, yscrollcommand=my_scrollbar.set)
      # Configure scrollbar
      my_scrollbar.config(command=my_listbox.yview)
      my_scrollbar.pack(side=RIGHT, fill=Y)
      my_frame.pack()
      my_listbox.pack(pady=15)
      # Add list of items
      my_list = ["One", "Two", "Three", "One", "Two", "Three", "One", "Two", "Three", "One", "Two", "Three"]
      for item in my_list:
      my_listbox.insert(END, item)
      my_button = Button(root, text="Delete", command=delete)
      my_button.pack(pady=10)
      my_button_1 = Button(root, text="Select", command=select)
      my_button_1.pack(pady=10)
      my_label = Label(root, text="")
      my_label.pack(pady=5)
      my_button_3 = Button(root, text="Select Multiple", command=select_all)
      my_button_3.pack(pady=10)
      my_button_4 = Button(root, text="Delete Multiple", command=delete_multiple)
      my_button_4.pack(pady=10)
      my_button["state"] = DISABLED
      my_button_1["state"] = DISABLED
      my_button_3["state"] = DISABLED
      my_button_4["state"] = DISABLED
      root.mainloop()

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

    feed the algorithm! great vid

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

    How to use scroll bar using place instead of pack?

  • @-eckes-w.3574
    @-eckes-w.3574 3 года назад

    How can i load and save the Lists. I want to make lists of suppliers and tools and want to save this and reload at Program-Start.

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

      You probably need to use a database then

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

    Can i make a list with a text widget? Because a did it and dont work :(

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

    could you pre-select an item, possibly using a variable? So when you open the app the listbox already has a selected item.

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

      You should be able to set something as default selected. If memory serves, it's something like:
      listbox.select_set(0)
      where 0 is the first item...change 0 to 3 to select the fourth item (listed items are numbered starting at 0)

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

      @@Codemycom thanks, I'll give it a try :)

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

    is there any possibility of creating an input fields within the list box
    i need this concept desperately

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

      Inside? You could hack something, but why not put it directly above or below it?

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

      Codemy.com yes iam doing a project will that be possible

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

    Sir how can we add scroll bar to the entire window with many widget like button label ....??

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

      I'll do a video on that soon. But it's the same way...add all your things to a frame and add the scrollbar to the frame.

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

      @@Codemycom hello there, i have got the same question, tried adding labels to the frame but didn't get the expected result.

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

      Hey, if you have figured it out, can you help me?

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

    My_listbox.insert(END, "this is an item")
    Sir ,why you take END in insert👆

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

      To add a new item (In this case that item is "this is an item") to the end of the list.

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

      @@slobodantajisic2762 yep

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

    Very good!

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

    hi man is it possible to add a scrollbar to a window ?

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

      maybe if you put everything in a frame

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

      @@Codemycom thanks for help

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

    Why does my reel automatically jump back to the top?

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

      Sorry, no idea what you're talking about

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

    My scrollbar appear ON TOP my listbox, why is that so? I follow everything u did

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

      I don't know, but you certainly did not follow what I did lol there's a typo in your code somewhere

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

    How to do if we want to append result in a csv file

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

      I have a whole course on that at Codemy.com
      codemy.com/python-excel-programming-openpyxl/

  • @ЕкатеринаВоронина-ж2ы

    thank you!!!

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

    Sir How to add scrollbar to a frame ?

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

      Tricky...might do a video on that someday

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

      @@Codemycom sir you can refer a website too or a sample code for the moment

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

      @@shlokdoshi7162 No, sorry

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

      There's a trick to this where you first build a canvas and then pack (or however you geometry manage this, but pack seems to work just fine) your scrollbar next to your frame with the canvas being the parent widget to both the frame and scrollbar. It apparently requires further code to then bind it to the canvas.
      I'd post the code syntax directly, but that'd take quite a lot of space and might not come out right in a comment, so I'll refer you to stackexchange which is a great resource for info and is a nice go-to in the future. Chances are, somebody already had your problem and found a solution to it ages ago and the answer is helpfully upvoted.
      Search terms I used for my solution are "tkinter scrollbar on frame." Warning, though, after you get this all done you'll then want to search "tkinter scrollwheel frame" as I don't think the scrollbar innately works with the mousewheel.

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

      @@crazyinsane500 Thank you.

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

    Anyone here from the Full Screen Scroll Bar video?

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

    100th like