▶️ 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
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.
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!
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.
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()
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.
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?
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 !
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.
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!
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
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
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?
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...
@@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.
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?
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?
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
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 :)
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.
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)
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.
▶️ 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
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.
Glad you like them!
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.
Thanks :-) I might..
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!
I appreciate that!
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.
Thanks! I make more every day, there are over 200 tkinter videos in this playlist alone :-)
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()
now I am trying to figure out how to make an undo button
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.
yep
Wonderful sir ...great teaching.... continue...
Thank you, I will
Thanks for such a great tutorial!, You deserve all the best!
Glad you liked it!
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?
I accept major credit cards (or their debit cards, ie MC, Visa etc) and paypal.
@@Codemycom thanks a lot
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 !
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.
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!
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
No, but that's a great idea for a video.
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
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?
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...
@@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.
Could I please get some help?
@@PKCubed uh, that's why root.mainloop() always goes at the end of your program. Don't put anything after it.
@@Codemycom Then how am I supposed to run the internal code for the chat?
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 ?
never mind. it seems that can't added scrollbar directly to a frame
yes you can put a scrollbar in a frame
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 ) ?
Might do a video on that one day
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?
I'm not sure you can really easily modify it.
It's really a greate job,thank you very much,i fix the problem of scrollbar
Glad to hear it!
Thank..good job...merci
Welcome!
@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??
i saw 15 of your vids today :D
watched*
@@amirmohammadk745 very cool!
i reckon you should firstly have used sorted, after reversed function cause we don't know how user will choose items in listbox
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?
Thank you very much You are the best! I'll nenver forget you
Thank you too!
Hello, I have a question. For example I learn tkinter pretty well and already write own app. Where I can publish my app?
Publish? There is no app store for these apps. You can build a website and sell it there, or give it away or whatever.
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
How do I use .grid with the scrollbar because it give error when you do .grid(side=RIGHT, fill=Y)?
Use .grid() in the same way you always use it. It's no different just because you're using it with a scrollbar...
@@Codemycom When I do that the scrollbar doesn't size, so it doesn't work
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 :)
PS: I also put yscrollcommmand to the List box, if you wonder.
Can I control the entire frame with widget in it usuing scrollbars? Apart from just lists?
Give it a try...
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.
Sorry, I can't know what's going on with your code in order to tell you what to do...
@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()
feed the algorithm! great vid
Thanks!
How to use scroll bar using place instead of pack?
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.
You probably need to use a database then
Can i make a list with a text widget? Because a did it and dont work :(
Sure you can.
could you pre-select an item, possibly using a variable? So when you open the app the listbox already has a selected item.
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)
@@Codemycom thanks, I'll give it a try :)
is there any possibility of creating an input fields within the list box
i need this concept desperately
Inside? You could hack something, but why not put it directly above or below it?
Codemy.com yes iam doing a project will that be possible
Sir how can we add scroll bar to the entire window with many widget like button label ....??
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.
@@Codemycom hello there, i have got the same question, tried adding labels to the frame but didn't get the expected result.
Hey, if you have figured it out, can you help me?
My_listbox.insert(END, "this is an item")
Sir ,why you take END in insert👆
To add a new item (In this case that item is "this is an item") to the end of the list.
@@slobodantajisic2762 yep
Very good!
Thanks!
hi man is it possible to add a scrollbar to a window ?
maybe if you put everything in a frame
@@Codemycom thanks for help
Why does my reel automatically jump back to the top?
Sorry, no idea what you're talking about
My scrollbar appear ON TOP my listbox, why is that so? I follow everything u did
I don't know, but you certainly did not follow what I did lol there's a typo in your code somewhere
How to do if we want to append result in a csv file
I have a whole course on that at Codemy.com
codemy.com/python-excel-programming-openpyxl/
thank you!!!
You're welcome!
Sir How to add scrollbar to a frame ?
Tricky...might do a video on that someday
@@Codemycom sir you can refer a website too or a sample code for the moment
@@shlokdoshi7162 No, sorry
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.
@@crazyinsane500 Thank you.
Anyone here from the Full Screen Scroll Bar video?
100th like
Sweet!