Тёмный

Open Excel Spreadsheet In Treeview With Pandas and Numpy - Python Tkinter GUI Tutorial  

Codemy.com
Подписаться 234 тыс.
Просмотров 41 тыс.
50% 1

In this video we'll import spreadsheet data from an Excel .xlsx file to our Treeview in Tkinter with Python.
To pull data from Excel, we're going to use Pandas and Numpy to do most of the heavy lifting. You don't need to know anything about Pandas or Numpy in order to do this, we'll pip install them and I'll show you everything you need.
We'll also use a Tkinter Filedialog box to select the excel file we want to open. Then our Treeview will be updated automatically.

Опубликовано:

 

10 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 127   
@Codemycom
@Codemycom 4 года назад
▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My RU-vid 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 ▶️ Get The Code bit.ly/3fLFQ8p
@ProgrammingTechStudent
@ProgrammingTechStudent 4 года назад
Your Python Tkinter Playlist is really helping the students and I'm one of them 😅😅😅 Thanks a lot Sir !
@Codemycom
@Codemycom 4 года назад
Glad you're enjoying it!
@pascalkop1479
@pascalkop1479 2 года назад
Greetings from the Netherlands in the EU (capital Amsterdam 👊🏻) Thank you so much for explaining everything. I really learn a lot from your RU-vid channel.
@Codemycom
@Codemycom 2 года назад
Happy to hear it!
@christoskarliampas9248
@christoskarliampas9248 2 года назад
It is in fact a series everyone interested in Python and Tkinter should follow, I found it very informative! Thank you so much, you helped me a lot to start programming my first GUI!
@Codemycom
@Codemycom 2 года назад
Happy to hear it!
@AruviTechNews
@AruviTechNews 3 года назад
Explaining the each and every line of program clearly..Thank you so much Sir...
@Codemycom
@Codemycom 3 года назад
So nice of you
@aavalos163
@aavalos163 2 года назад
Great tutorial. I actually applied this to my vehicle inventory query app and added vertical and horizontal scrollbars. Thank you.
@Codemycom
@Codemycom 2 года назад
Nice
@muneebkhan189
@muneebkhan189 3 года назад
I'm making a POS software and your videos are helping me a lot.
@Codemycom
@Codemycom 3 года назад
Glad to hear it!
@RyanDanielG
@RyanDanielG 3 года назад
Smash that like button guys n gals! its free! great python tkinter tutorial, Codemy. Thanks
@Salila_Dinendra
@Salila_Dinendra 3 месяца назад
Thank You for the video. ❤❤❤
@Codemycom
@Codemycom 3 месяца назад
Welcome!
@YK-fd2hf
@YK-fd2hf 4 года назад
Thank you SO MUCH for this tutorial, I have been looking for one of these for a while now
@Codemycom
@Codemycom 4 года назад
Glad you like it!
@brijesh7146
@brijesh7146 4 года назад
@@Codemycom Codemy i have a question i am a beginner and i want to know if Tkinter is used every time in python or is there any other way to make general user interface without Tkinter
@Codemycom
@Codemycom 4 года назад
@@brijesh7146 There are many different tools to make GUI stuff with Python, not just tkinter
@krishnanandshenoy2841
@krishnanandshenoy2841 4 года назад
Thanks you sir for this amazing tutorials ...helped me a lot in my project 🙏
@Codemycom
@Codemycom 4 года назад
Glad it helped!
@andreboss6053
@andreboss6053 2 года назад
Great video. Very informative and well explained
@Codemycom
@Codemycom 2 года назад
Thanks!
@fernandomartino4708
@fernandomartino4708 Год назад
is there a way to automatically adjust the column width depending on the width of the text in the columns? How could be done this?
@ajsunofficial6798
@ajsunofficial6798 Год назад
John how about not opening the file..but we have a dialogue box and we give them a word or code and it reads thru a folder with multiple pdfs and brings it back in on the screen relevant information say a line or two of the word or the code
@alialavizadeh2775
@alialavizadeh2775 3 года назад
thank you Mr Elder for this cool contents 👍
@Codemycom
@Codemycom 3 года назад
You're very welcome! Thanks for watching!
@user-xx9di3bw7d
@user-xx9di3bw7d Год назад
Hi sir, how about open a specific sheet for example is I only want to show to my treeview the sheet 2 in excel?
@ikrameounadi7075
@ikrameounadi7075 2 года назад
HELPP PLEASE !!!! i'm working on a project , the main page has upload button and search button , i uploaded the file like you did in the command of the upload button so when i press the button i get a new window with this video content , but when i close it the data is not saved , i want to use the search button to get information from the excel file uploaded in the content of the upload button . MY problem is i don't know how to save the data when i close the window , and how to make the search .
@AmandaSalisbury-ib9fw
@AmandaSalisbury-ib9fw Год назад
My except error code is not being run after an exception. If I run file_open(): I get the open file window, but if I close it without choosing a file I get the FileNotFoundError. Then my program freezes up and I can no longer open a file due to locked database. It never executes what is inside the except error code. Added the print to see if there was something wrong with my label, and it never showed up. I also added text to the label where it was created and it did show up. if filename: try: filename = r"{}".format(filename) df = pd.read_excel(filename, header= None) except FileNotFoundError: print('Did This Work?') my_label.config(text="File could not be Opened") except ValueError: my_label.config(text="File could not be Opened")
@devenjain7116
@devenjain7116 3 года назад
Is it possible to open only selected columns from a spreadsheet instead of the entire sheet?
@Codemycom
@Codemycom 3 года назад
Sure, I have a whole course on using excel and python at codemy.com
@devenjain7116
@devenjain7116 3 года назад
@@Codemycom Thanks! I figures it out, used csv reader and iterated through the columns I wanted
@aceofspades02
@aceofspades02 10 месяцев назад
I did everything but it gives me the error "file not found". Maybe something is missing between the lines "filename = ..." and "pd.read_excel()..." ?
@aceofspades02
@aceofspades02 10 месяцев назад
I skipped the try, and added a dictionary manually, just to test the treeview, and it worked fine. so, yes... after 12 years of experience in python, I still hate numpy and pandas. I always end having to make everything on my own.
@shreyashprakash6538
@shreyashprakash6538 4 года назад
NIce i have been watchin all ur vids recently
@Codemycom
@Codemycom 4 года назад
Nice!
@sathyabhat3210
@sathyabhat3210 Год назад
Can anyone tell me how to keep this treeview window dynamic!! For Ex : If the content changes in .CSV file, it should automatically update in treeview window.. Please guide
@netanellevi2344
@netanellevi2344 4 года назад
Thanks !! the video is perfect !
@Codemycom
@Codemycom 4 года назад
Glad you liked it!
@adistar-964
@adistar-964 4 года назад
awesome!!!
@Codemycom
@Codemycom 4 года назад
Thanks!
@devenjain7116
@devenjain7116 3 года назад
Hey, is it possible to group data be a particular column and then display it? Fir example if multiple records have the the same value of one column, say the "Name" column, is it possible to add the first one to a parent and create a child which contains the rest of the data?
@Codemycom
@Codemycom 3 года назад
Sure probably
@devenjain7116
@devenjain7116 3 года назад
@@Codemycom Whenever possible, please do make a video on how to search dynamically a csv file using Treeview. Just like you did that Listboxes, thank you!
@oscarroman4901
@oscarroman4901 3 года назад
Is it possible to show up specific rows and columns from a DataFrame on the Treeview? Hoping you can give me a hand?
@devenjain7116
@devenjain7116 3 года назад
Is it possible to click on a record in Tree-View and clicking on it automatically fills in all the data from that record in the corresponding entry boxes available on the screen?
@Codemycom
@Codemycom 3 года назад
Yeah, I have a video on that in the playlist that I'm doing right now (the last few videos, most recent).
@devenjain7116
@devenjain7116 3 года назад
@@Codemycom Yeah i found that one! However, I am not able to figure out how to search dynamically using Treeview. I can perform search on nested lists from CSV files easily, but I want it to look dynamic so that it looks more pleasnig to the eye, like you did search on List Boxes, that kind of thing is possible on Treeview?
@Codemycom
@Codemycom 3 года назад
@@devenjain7116 Sure but I don't have videos on it. Maybe I'll make one
@devenjain7116
@devenjain7116 3 года назад
@@Codemycom alright, thank you for the help, I really appreciate it! Because of you I am able to build full stack GUI applications on Python for myself and my friends! :) I can't thank you enough
@Codemycom
@Codemycom 3 года назад
@siddanna arakeri no thanks
@brunobarros1076
@brunobarros1076 2 года назад
Sir, how can I align the values ​​in the center of the column?
@adhdGameDev
@adhdGameDev Год назад
I get " NameError: name ´df´ is not defined" in: my_tree["column"] = list(df.columns) what could be the reason?
@Codemycom
@Codemycom Год назад
what did you do differently from the video?
@adhdGameDev
@adhdGameDev Год назад
@@Codemycom i have watched and rewatched the video and from what i can tell.. nothing. Thanks for incredibly fast response! heres my "treeview section" if that helps: #setup new treeview my_tree["column"] = list(df.columns) my_tree["show"] = "headings" #loop through column list for headers for column in my_tree["column"]: my_tree.heading(column, text=column) #put data in treeview df_rows = df.to_numpy().tolist() for row in df_rows: my_tree.insert("", "end", values=row) #pack treeview my_tree.pack()
@adhdGameDev
@adhdGameDev Год назад
fixed it.. stupid mistakes
@Vibhu__Khullar
@Vibhu__Khullar 4 года назад
The Tkinter textbox i doing some weird stuff, whenever I m working with the text widget and press (Control+i, Control+h, Control+k), it start doing weird stuff like:- Control+i - is deleting all the selected text (the text under selection tag). Control+h - is working somewhat like a Backspace key. Control-k - removes all the text at the right side to the position of cursor. Do you know some trick to fix that? Like it's messing up the things if i wanna bind some event or function with these key combinations, like I wanna use Control-Key-I for Italics function
@Codemycom
@Codemycom 4 года назад
No clue...mine doesn't do that. Did you code it to do that?
@Vibhu__Khullar
@Vibhu__Khullar 4 года назад
@@Codemycom NO, I even tried writing a new code from tkinter import * root=Tk() t =Text(root, width=50, height=50) t.pack() still it does the same thing as I mentioned earlier.
@Codemycom
@Codemycom 4 года назад
@@Vibhu__Khullar Weird
@henriquetavares6588
@henriquetavares6588 2 года назад
John, is it possible to do a delete columns function that works with the spreadsheet we see in the Treeview ?
@henriquetavares6588
@henriquetavares6588 2 года назад
If so, could you do a video on the subject ?
@muneebkhan189
@muneebkhan189 3 года назад
Thanks a lot man
@Codemycom
@Codemycom 3 года назад
Sure thing!
@abiolaolaleye1134
@abiolaolaleye1134 4 года назад
Gracias señor
@Codemycom
@Codemycom 4 года назад
You're welcome!
@tribaldcon
@tribaldcon 3 года назад
thanks... however, pyinstaller is having issues with pandas.
@rogeriovaz4420
@rogeriovaz4420 4 года назад
Great.
@Codemycom
@Codemycom 4 года назад
Thanks!
@johnmarigu548
@johnmarigu548 Год назад
Hi Teacher, Am John from Kenya. Kindly create a video on how to print tkinter treeview data. Am trying it but it's printing blank page. Thanks.
@stegabilly
@stegabilly 3 года назад
Yeah, I'm struggling with this. I copied your direct code from Github and amended the initial directory and deleted the icon line. I'm given the Value Error message from the Exception handling code that was entered. And this (I shortened the file directories): Exception in Tkinter callback Traceback (most recent call last): File "C:\...\Python39\lib\tkinter\__init__.py", line 1892, in __call__ return self.func(*args) File "C:\...\File.py", line 36, in file_open my_tree["column"] = list(df.columns) UnboundLocalError: local variable 'df' referenced before assignment I'd love to get this working. Any ideas? Cheers
@Codemycom
@Codemycom 3 года назад
I'd never copy paste code from github, it can lead to all sorts of errors. You have a program flow problem, it's telling you what it is. You are referencing the variable df before you are assigning anything to it.
@stegabilly
@stegabilly 3 года назад
Thanks for replying. Following the code through, I assume the reason it references the df variable before it is assigned is because the df variable is created inside the "try" statement. I'm strugging on why a ValueError Exception would be raised in the first place rather than the try statement being run. I've tried a couple of xlsx files. I'll have a Google.
@stegabilly
@stegabilly 3 года назад
So I just tried reading an excel file using:: df = pd.read_excel and that didn't work, but I got a different Error message which was more helpful; it turns out I just needed to install openpyxl. Now I feel silly. That's what I get for jumping into te middle of a course. All sorted. Cheers
@89SuperIan
@89SuperIan 3 года назад
@@stegabilly Man, I am very stuck here. I'm getting the same errors you were getting. All you had to do was install openpyxl? That didn't fix my problem.
@dianjinxu5127
@dianjinxu5127 2 года назад
Thank you for the tutorial. One thing that bothered me was the .filetype command. I tkinter is using .filetypes in the current version instead.
@Codemycom
@Codemycom 2 года назад
Sorry, no clue what you're talking about
@bathuano2757
@bathuano2757 3 года назад
sorry sir, i can't know it my_tree["column"] = list(df.columns) Unbound Local Error: local variable 'df' referenced before assignment
@thenaturat666
@thenaturat666 3 года назад
I have that same error, even when I copied code from John's GitHub
@thenaturat666
@thenaturat666 3 года назад
i've tried to delete try/except blocks because i've had in my app ValueError message which we designed in our app, and run the file without them (only with code form try block) and than i had different error: ValueError: Your version of xlrd is 2.0.1. In xlrd >= 2.0, only the xls format is supported. Install openpyxl instead. I've changed the excel files to .xls and everything works fine
@Kotavedavyas
@Kotavedavyas 3 года назад
sir CSV file is not opening with it
@tazulislam2698
@tazulislam2698 2 года назад
There are not shown more than 1600 rows in treeview table. Need to show more than 5000 rows. pls make a tutorial in this regard.
@KornJohnGaming
@KornJohnGaming 4 года назад
Great video John. Could you possibly do a video regarding taking an sql database and slapping it onto a treeview?
@Codemycom
@Codemycom 4 года назад
I have videos on grabbing data from sqlite already...and now you know how to insert into treeview from this and the last few videos...you should have what you need...
@gopinathsonu
@gopinathsonu 3 года назад
How to add search field in this, which works dynamically filtered with data ? Thanks in advance
@Codemycom
@Codemycom 3 года назад
I have videos on search on the playlist
@neilthomas2549
@neilthomas2549 3 года назад
Way to open a file? I just use the string returned from filedialog, rather than converting it to a string.
@aviralkaushik3171
@aviralkaushik3171 4 года назад
Sir, I want to ask that can we convert .py file to .apk file or not?
@Codemycom
@Codemycom 4 года назад
no you can't
@aljoeanthonyberdin2845
@aljoeanthonyberdin2845 2 года назад
how should fix this error >>>> ModuleNotFoundError: No module named '_typeshed'
@Codemycom
@Codemycom 2 года назад
stackoverflow.com/questions/61532337/python-modulenotfounderror-no-module-named
@shrutimishra5497
@shrutimishra5497 3 года назад
Hello Sir, I tried this code but the filemenu was not added somehow so i cannot see the menu to open the file also there is no error i cannot understand what should i do
@Codemycom
@Codemycom 3 года назад
Check your code for typos...it has to be exact.
@shrutimishra5497
@shrutimishra5497 3 года назад
@@CodemycomI checked for the typos many times but the file_menu.add_command(label="Open", command=file_open) is not working which is why there is no Open menu when i checked and also no error is being shown
@Codemycom
@Codemycom 3 года назад
@@shrutimishra5497 Things don't just "not work". They don't work because you wrote the code wrong somewhere.
@shrutimishra5497
@shrutimishra5497 3 года назад
@@Codemycom Thank You Sir, I wrote the Menu code again and it worked.
@Codemycom
@Codemycom 3 года назад
@@shrutimishra5497 Awesome! Glad you got it sorted out.
@shubhammali2072
@shubhammali2072 2 года назад
It is possible with csv file ?
@Codemycom
@Codemycom 2 года назад
of course
@alwynjoby9604
@alwynjoby9604 3 года назад
Sir how do we fix the width in the case of importing excel file?
@Codemycom
@Codemycom 3 года назад
Not sure what you mean
@alwynjoby9604
@alwynjoby9604 3 года назад
@@Codemycom Sir, when we put data in treeview, can we preset the column width?
@Wittytime98
@Wittytime98 4 года назад
Hello sir, I have an question about django related quries sir "how to insert multiple images in carousal using django" i request you plz give me an answer its very important
@Codemycom
@Codemycom 4 года назад
this is a tkinter video
@Wittytime98
@Wittytime98 4 года назад
@@Codemycom yes sir i know but i have done only for fast reply
@Wittytime98
@Wittytime98 4 года назад
I have completed a blog project from your tutorial and learns lots of things
@Wittytime98
@Wittytime98 4 года назад
Could be done anything for my question
@Codemycom
@Codemycom 4 года назад
@@Wittytime98 It's not something I can explain in a comment here
@chinmayboddawar5809
@chinmayboddawar5809 Год назад
how to Open Exel Spreadsheet in Grid ?
@Codemycom
@Codemycom Год назад
in grid?
@ajinkyadalvi4761
@ajinkyadalvi4761 2 года назад
Sir can you please make a video to add scrollbars to browse excel file in tree view.
@Codemycom
@Codemycom 2 года назад
I have plenty of videos on scrollbars with treeview...but you don't ever put excel files in a treeview. That's not what treeview does.
@abdulmugees2787
@abdulmugees2787 2 года назад
Traceback (most recent call last): File "c:\Users\MAA\OneDrive\Desktop\WaySoul\pract.py", line 148, in file_menu.add_command(Lable="Open",command=file_open) File "C:\Users\MAA\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 3302, in add_command self.add('command', cnf or kw) File "C:\Users\MAA\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 3289, in add self.tk.call((self._w, 'add', itemType) + _tkinter.TclError: unknown option "-Lable"
@abdulmugees2787
@abdulmugees2787 2 года назад
why this error show on code
@Codemycom
@Codemycom 2 года назад
@@abdulmugees2787 lable should be lowercase, always.
@abdulmugees2787
@abdulmugees2787 2 года назад
@@Codemycom thanks sir
@Codemycom
@Codemycom 2 года назад
@@abdulmugees2787 welcome
@shehab976
@shehab976 3 года назад
No big boooom today😔
@Codemycom
@Codemycom 3 года назад
Ha
Далее
Bacon на громкость
00:47
Просмотров 112 тыс.
Automate Excel Work with Python and Pandas
21:29
Просмотров 96 тыс.
Tkinter - Treeview Create Columns and Insert rows
18:07
Python GUI open a file (filedialog) 📁
7:38
Просмотров 97 тыс.
Bacon на громкость
00:47
Просмотров 112 тыс.