Create GUI App with Tkinter and SQLite - Step by Step Python Tutorial for Beginners
HTML-код
- Опубликовано: 2 июн 2024
- Today we will create a highly sophisticated Tkinter application, which is PERFECT for beginners and even intermediate Python developers!! 💻💻💻
In this tutorial, we will:
⭐ connect an SQLite database of recipes to our app.
⭐ create a BEAUTIFUL graphic user interface with Tkinter.
⭐ randomly shuffle recipes and display them on the app.
⭐ preprocess table records.
⭐ use CUSTOM FONTS with Tkinter (works with Windows only).
I will guide you step by step, explaining each command, the logic behind it and even different approaches we can take!
This tutorial is designed especially for folks who are comfortable with Python but struggle to apply it in practice. Additionally, complete Python beginners will get all the instructions they need to keep up the phase! 😀
🛑🛑 Convert This App into a Professional Software 🛑🛑
-----------------------------------------------------------------------------------------------------------
Tutorial is now available (including a relational database fix!!!):
• Convert GUI App to Rea...
-----------------------------------------------------------------------------------------------------------
Download Starter Files (and Complete Project Files):
github.com/MariyaSha/RandomRe...
Install dependencies (Anaconda):
🐍 conda install -c anaconda tk
🐍 conda install -c anaconda pillow
🐍 conda install -c anaconda numpy
🐍 conda install -c conda-forge pyglet
Install dependencies (Pip):
🐍 pip install tkinter
🐍 pip install pillow
🐍 pip install numpy
🐍 pip install pyglet
----------------------------------------------------------
📽️ Other Related Tutorials of Mine 📽️
----------------------------------------------------------
⭐ Install Python with Anaconda:
• Anaconda Beginners Gui...
⭐ SQLite Basics:
• SQLite Backend for Beg...
⭐ Web Scrape Databases with SQLite and Mechanical Soup:
• Web Scraping Databases...
⭐ Create simple GUI app with Tkinter:
• Create a GUI app with ...
⭐ Create advanced GUI app with Tkinter:
• Create GUI App with Tk...
----------------------------------------------------------
⏰TIME STAMPS ⏰
----------------------------------------------------------
00:00 - intro
00:25 - starter files and wireframe
01:09 - create empty Tkinter window
01:33 - run Tkinter app
02:43 - set window title
02:58 - center window on the screen (Eval method)
04:00 - create Frame widget with custom width, height and background
05:32 - center window with Geometry method (alternative approach)
06:58 - create image widget
10:03 - center widgets in frame with pack propagate
11:01 - create Label widget
11:49 - fonts in Tkinter
13:20 - create Button widget
13:56 - change cursor to pointing hand
14:47 - button callback and why lambda is important
16:21 - add padding around widgets
17:05 - code refactoring
20:08 - connect SQLite database file
22:01 - database architecture walkthrough
23:54 - select all table names of a database with SQL
25:18 - fetch random database tables with SQL and NumPy
26:25 - fetch table records
27:56 - preprocess table name and records
30:09 - conditional list comprehension
34:45 - switch between frames
38:31 - remove widgets from frame
40:43 - sticky (remove white corners)
41:45 - label background in full window width
42:41 - use CUSTOM FONTS in Tkinter
43:24 - Pyglet
45:23 - Thanks for watching! :)
-------------------------------------------
🤝 Connect with me 🤝
-------------------------------------------
🔗 Github:
github.com/mariyasha
🔗 Discord:
/ discord
🔗 LinkedIn:
/ mariyasha888
🔗 Twitter:
/ mariyasha888
🔗 Blog:
www.pythonsimplified.org
-------------------------------------------
💳 Credits 💳
-------------------------------------------
⭐ Database web scraped from:
cosylab.iiitd.edu.in/recipedb/
⭐Switch between frames on StackOverflow:
stackoverflow.com/questions/7...
⭐ Beautiful icons:
flaticon.com - Наука
You are very sympathic and you have a talent for clear explanations,,
but i think it would be better to teach sql from the beginning like it is meant to be.
Sql is an relational database what means you would structure that case differently:
Only two table are needed: The first table (name: Recipies) holds an id and name (recipiename) column. The second table (name Ingridients) holds following columns: another id, Recipies_Fk (foreign key, pointer to the id column of the first tabel) and then all the ingridient fields. Thats it. Now the table name of your sql statements are static. But you need now more sql statments: "Select * from Recipies" select a random line in the pyhton code and pass the id to the follwoing statement "Select * from Ingriedients where Recipies_Fk = ;".
You also gain there big advantage which is that you are only loading the neccessary ingridients.
Thank you so much for the AWESOME tip Justic!! 🤩🤩🤩 I must admit - I didn't even think of this type of database architecture! At first, my thought was to store each recipe as a separate record on the same table - but the different number of ingredients was quite the deal breaker 😅
Instead of looking at ingredients and recipe names as different entities altogether - I combined them into one 🙃
Your suggested architecture is a million times better than what I came up with, so thank you so much for sharing it!! 😃😃😃
Yeah she definitely has to do more with the database design but your tutorials saw amazing. Keep up
Thank you for the video ... how can i convert Tkinter desktop App to Web App
@@japhethjay4880 an updated version of the app is now available (based on a relational database of course 😉):
github.com/MariyaSha/RandomRecipePicker/tree/main/relationalDB_complete_project_WINDOWS
Currently working on a tutorial that converts it into a full-blown software (suitable for all operating systems with Inno Setup) 💪💪💪
Folks, an updated relational database version of the app is now available:
github.com/MariyaSha/RandomRecipePicker/tree/main/relationalDB_complete_project_WINDOWS
Will see you soon in a brand new tutorial that converts it into a full blown software suitable for all operating systems (auto-py-2-exe + Inno Setup) 😁😁😁
This lady is a fantastic teacher and dedicated to her work. At one point she is savagely attacked by what appears to be wild cats and she carries on with the class....
Tkinter GUI + Database = Exactly what I was looking for !!! Thank you ❤️
I keep saying CORSORE to my friends out of context. You have changed the word forever for me.
I just started learning Python and I was lucky to come across you videos which made me not only fall in love with you and your way of explaining complex concepts with simple words but fall in love with Python... It's a pleasur to whatch and hear you teach.
You’re such a fantastic teacher. You make it sooooo easy to understand. You should make a full python course. I’d love that
I'm used to learn new Python things from Indian Developers, which I hardly understand, so it's very refreshing to see and listen to you. Also the Cat accident is very relatable, since my cat alwys do such things
Exactly what I wanted! The doc said I need to log my blood pressure daily and I want to create a simple gui that I can input the values and a button to update a database, and also show a plot for the values and stuff. This video will be very useful!
This is the best tutorial on GUIs I have ever seen. Good job!
Hi Mariya. I just finished the recipe picker project. I learned a lot. It is great to see how different programmers approach coding. I hope you produce more videos. Take care.
Finally, someone talks like a real person, instead of with those "programmer voice" like in most online tutorials.
At 14:49 you could also just remove the parenthesis on the function. When you assign the function with parenthesis you assign the functions return value, which in this case is None as it doesn't return anything, and the function is executed at assignment. Lambda is mostly useful when you need a non-default sorting key, or when you are only changing one argument.
Say for example, you inject a function into a class. You have a function triangle_area(bottom_side: float, angles: Tuple[float, float, float) -> float. But in your class the angles are always 60 degrees and it only takes a function triangle_area(bottom_side:float) -> float, so instead of making a brand new function, you pass it a lambda function Lambda x: triangle_area(x, (60,60,60)).
Wow Maria! That was beautifully done. Nice and clear, explained well and easy to follow. I will be watching a lot more of your videos. Thanks!!
Thank you so much Robert! Glad you liked it! 😃
This was a great presentation. The way you develop an app is the way most programmers think, I believe. At least it's the way I think. I have been away from Python for a couple of years, so this was a great review for me. I'm writing an app that uses SQLite 3 to query a database with a table of 40,000 lines. The queries are complex, but there is only one table.
I usually use PySimpleGui, but there are some widgets that I need that PySimpleGui doesn't have -- like a tree control with checkboxes.
Love your videos!! fixing to start a tkinter project that uses sqlite this is a great intro. At first I thought you were saying costume fonts. I had to watch till the end to learn what they were lol.
Very happy to see a woman explaining python stuff, thank you.
When I want to make a gui tkinter project and also with SQLite3 the first youtube channel your channel will the first recommended channel in my mind
This is a good tutorial, it explains how to create a window and render a button attached to a function. Database connection is great and simple.
There is a lot of hacky code, midway to the end.
This tutorial is a mouthful, but now I'm interested on learning Tkinter properly on Udemy.
Seems like Tkinter is what Java tried to do back in the 2000's to allow Java developers to make graphical user interfaces using Java.
I just been thinking about how to use tkinter. Thank you yt algorithms, and thank you too python simplified! :D
hahahaha so happy the algorithms got you here Johnny!!! 😊
I also have a bunch of other cool Tkinter tutorials which you might find handy (focusing extraction of text and images from PDF files):
⭐ Create simple GUI app with Tkinter (short 20 minutes video):
ruclips.net/video/itRLRfuL_PQ/видео.html
⭐ Create advanced GUI app with Tkinter (much longer video, same app though):
ruclips.net/video/y8PR4lTAh5E/видео.html
Good luck with Tkinter! I hope it helps! 😀😀😀
After having almost finished the video, I’m back again to say, amazing and thank you!
I got 9 minutes in, and every minute was clear, practical, and perfectly explained. Subscribed! I will continue watching on weekend when I have more time. You have an excellent teaching style.
Thank you so much for the lovely comment Ryan! 😃
I hope you like the rest of it too 😉 (once you're back, please checkout the pinned comment up top suggesting how to improve the structure of my database, I really wish I figured it out on my own hahaha 😅)
Again, awesome education video! Learning a lot of stuff which are useful in my tasks. Thanks for your knowledge sharing :)
I know theirs a lot more work that goes into these videos to make them so smooth, but damn are they smooth. Thanks for another great tutorial!
Thank you for this, I followed it all the way through, typing in the code myself and learnt loads. This is just the right kind of pace for me 👍
Fantastic!!! 🤩🤩🤩You're absolutely welcome, Paul!!
BTW, you can now convert this app into a real program that anyone can download and install on their computer! :)
Checkout my recent tutorial from last week (designed specifically for the Random Recipe Picker app ;)):
⭐ Convert GUI App to Real Program - Python to exe to setup wizard
ruclips.net/video/p3tSLatmGvU/видео.html
Very straightforward and easy to understand. You might say… _Python Simplified_ . Thank you!
Excelent tutorial. Keep up the good work. I really enjoyed it and it also got me thinking about it so I have made some additions. I noted that title always start with " " due to space addition while splitting words so I removed that extra space. Second thing I noted is some recipes have quite long titles so I made adjustment to break it down and insert "
" after 3 words.
This is what I added in "load_frame2" right after call of "pre_process" function:
title = title[1:]
if title.count(" ")>3:
split_title = ""
title_words = title.split(" ")
i = 1
for w in title_words:
split_title += w + " "
if i % 3 == 0:
split_title = split_title[:-1]
split_title += "
"
i +=1
title = split_title[:-1]
What a lovely girl! and a great teacher! I wish I had a teacher like this 10 years ago. Clear explanations! Charming! and reads your mind.
When you say: why are you.....
She says: and if you are thinking about this: here is the answer hahahaha. amazing! Keep Rocking!
I ABSOLUTLY LOVED this Video, it was super clear and you made eveything look so simple and easy
Thank you so MUCH for the effort u put into into, Keeping the code zoomed in was the best thing, it helped A LOT
Please keep the same video style and im highly looking forward to the next video.
i was honestly feeling down recently because i could not understand some tutorials, but your video really boosted me and my confidence to keep learning. Take Care Maryia💗
Thank you so much for the incredible comment Alan!!! 😀😀😀
I'm super happy to help, will keep it up for sure!! 😉
@@PythonSimplified
H
This is my first time to watch a video from your channel. And i was amazed by your way of explaining things. I am eager to see your other videos. Keep gooing, really really amazing..
Você é d + loura ! Linda inteligente e exelente programadora ! Meus sinceros parabéns pelo sucesso linda!
Mariya, you do an awesome job explaining the code and I love watching your channel! Keep up the great work!
Thank you so much Clay!!! Will do!! 💪💪💪
This was a first video witch i watched) And i really like it! ❤️👍 So i will now watch your tutorials. I started to understand English quite recently😅. It will be great practice for me)
cool video, you just gained a new subscriber ;)
not a beginner in python but was always curious on tkinter topic
I liked the way you teach.. I just started learning python, luckily found this video.. thanks for sharing your knowledge/skills.
well done ! that was fun to watch and really good explanations !
It was an indeed worthy tutorial. 45 minutes spent with a brilliant teacher. Thank you ❤ Greetings from Poland :)
Impresed as easy you teach! 👏👏
Thank You Again for this GUI App video ;)
Never thought that creating a Tkinter app could be that easy.
your tutorial is great. Thank you
Thank you so much Yaron! 😃
שמחה לשמוע שאהבת! ד"ש מוונקובר! 😉
Wonderful video tutorial. One of the best on the internet! Thanks a lot for your teaching quality. Have a nice day!
your videos are extremely helpful for the beginners! I often recommend them to friends who are getting started with python.
Yeey! Super happy to hear!!! 😀
Thank you so much for the support! 😊
Your tutorials makes me love python more and more. Thanks keep it up.😍
You have a killer way of explaining stuff. Your concepts have furthered my career so thanks.
Thank you for this hudge complet and easy TkInter tuto. Very clear.
Maybe my libs are a "little" to old, but :
- from PIL import ImageTk raised a import exception. So, i use logo_img = tk.PhotoImage(file="assets/RRecipe_logo.png") and it works.
- SQL command "SELECT * FROM sqlite_schema WHERE type='table';" didn't work, So, i use "SELECT * FROM sqlite_master WHERE type='table';"
If it could be usefull to someone ...
Put root.eval("tk::PlaceWindow . center") just after load_frame1() seems to be nice too ;)
Excellent explanation mam. I got some ideas to make GUI application in Python. I also get how to handle sqlite3. Thank you mam. Exactly I need this. Past 3 days i had been searching for this. Thank God, Finally you help me a lot. Thanks a lot mam.
Hi Maria, yo're amazing and create the best tutorial I've ever seen for beginner! :)
Thanks a lot for the time put in this video. You helped me a lot with your clear explanations and your cheerfull attitude made it so easy to follow you every step. Looking forward to watch some more of your content!
Keep up the great work ^^
Thank you so much for the lovely comment Neji! 😁😁😁
Thank you for the video ... how can i convert Tkinter desktop App to Web App
Great tutorial! Subscribed.
I was weirded out by the font changing to default Windows font when I added the custom Ubuntu and Shanti fonts. Then, I realized I need to install them first on the machine 🤣. Thank you for your knowledge, teacher!
I'm simultaneously thrilled and furious to learn how easy it is to center the app on the screen with just that root.eval("tk::PlaceWindow . center") method. I've gone to extensive lengths before for worse-looking behavior.
This is an incredible tutorial and I learned a lot, thank you for this
Start: Too beautiful to be a programmer
Mid: Damn, she can cook as well!
Your application is too easy to implement, thanks for your contribution.
I love the way you explain and speak even me that i'm not native from English i can understand. Blessings.
Hi Mariya. You impressed me with your knowledge and the way you explain the hard programming issues. Thank you.
You are a great instructor… loved your videos 💫
Мария ты лучшая! Супер урок!
Thank you so much for this amazing tutorial!
Thank you Mariya. Your teaching is excellent. Thanks for sharing.
Even tough I done some tkinter before this was among the best spent hour this quarter.
I will watch this again.
She is actyally moore fun and intelligent then she is 🤩, witch is actually amazing.
She should expand on this beutifull app, I have to understand how to make an export XML-file. I think this is a very good start tough, but it needs some good looking Entryfields as well.
Great content!
C'mon, sis, get 100k ❤
You are excellent teacher and expert for Python.
Congratulation.
u really save me in my report for the last subject of semester
omg, havent use tkinter for over 5 yrs now. I remember I was also able to package the whole tkinter project into an exe
Subscribed your channel within 5 minutes of your teaching
Thanks for the intro! Just finished coding a database app (with pandas). :) Dr J
Congratulations in 100k!
You are a fantastic teacher !!! 🏆🏆🏆🏅🏅🏅🙏🤗
Hi Mariya! Thanks for such a great video!
I like this very much. You do a great video. I'm going to try the pancake recipe.
Hi Mariya ! Very nice. Helped me a lot to develop for MySQL application. Thanks.
Best Pancake recipe ever!
love your accent... very similar to my wife who's Russian with very good/excellent English.
Congratulations for 100k subscriber beautiful ❤️
I love the ton of your voice.
Keep going this is amazing
Hey mariya...
I can't thank you enough for making this video... This video has broken me out of a loop. I was stuck here. Like data basee and ****** tkinter 😅😅😅
So... I thank you alot...
Learning alot from you...
A coding video with a beautifull face. What else can i wish for ❤️😁😁
Anywas. Thanks ❤️❤️☺️
Love your tutorial 😍☺️
Thank you very much for this tutorial 👍
😅You are so amazing, thank you, good luck
Love this tutorial
Another helpful tutorial will be, how to download a file from a url (for example an image from google drive) with the click of a button. Love your videos!☺️❤️
Not sure if it will work for Google Drive as your files are private there, but when you want to download any file from the web, a great library to use is wget 😃
I demonstrate how to use it in the end of this tutorial:
ruclips.net/video/drDdb1MBBfI/видео.html
Good luck and I hope it helps! 😊
Hahahahaha 🤣, let me learn to "force it".
Thanks lady, I like the energy
awesome tutorial. One feedback, we should make the ingredients scrollable as when a large list pops up the button is nowhere to be seen. apart from that it looks complete.
In love with this
you give of such positive vibe damn
Thank you for all the tutorials and videos.
Im new to python and looking at doing a mobile app with kivy.
Any chance you have a video or can make one with kivy linking to mysql (login and pulling data from a table etc.)
Hello, Maria this is an awesome explanations,, well done Maria 🥰🥰🥰
HI maria, thanks for this lesson, will you make a complet crud in the future for this application ?
2:06 your desk, is mine too 😹😹😹😻
Good practices greetings from Mexico, your videos are very good....!!!
Great video I learned alot
Excellent content thank you so much for your work. 🙏
Thank you very much!
Thank you for your tutorials they're very helpful
Thanks my dear i am just say i love you for your support thanks again
I think I'm in love with Python because of this
Bigggg FAN
🔥
Hi Mariya, I'm new to python and to your channel, just watched a few of your videos, and I must say you are one the few channels teaching python that is easy to understand and follow, thank you. Would it be possible for you to create a tutorial about an app that I can use a base app that I can build upon? The app that I would like to build is an app for recording data/information that I will get from a scanned pdf document, so the app would have two panes/grids one for encoding the Data Record and One for viewing the Pdf File, I need to somehow mark the pdf file if it was encoded already and save the data to a database or excel or csv file, can you demonstrate how to accomplish this, maybe a simple contact information app that will get the info from a scanned pdf file of a contact form just to demo the concept. Thanks in advance...
thank you for the video and the best explanation.
Thank you for the lovely comment! :)
Thank you Mariya! I like it when you explain each step. I'm on a Mac and tkinter doesn't allow me to control colours for buttons. I used a module called 'tkmacosx' which at least give me some control. Now I know why I prefer Qt when dealing with a GUI.
Look into ttk (yes, two tees)) to work around this and get better native macOS support.
I had an issue fetching the database at 25:17 using cursor.execute("SELECT * FROM sqlite_schema WHERE type='table';")..... got it working using cursor.execute("SELECT * FROM sqlite_master WHERE type='table';")
Great job by the way :)
This also was a resolution for me.