Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Dates with Sqlite and tkinter (Laptop booking part 2)

Hey Pythonistas, unsure of how to work dates/sqlite/tkinter into one fluid system, hoping someone can give me some resources to help me learn a bit more about it.

What do I want to do?

Well I'm making a laptop booking system and I am planning to create a grid of buttons Placed in a frame and I want each button, when clicked, to allow the user to book X amount of laptops for a specific date and time.

It will check the db for availability, output the available amount, if > 0 then allow booking, they input amount on messagebox prompt. Then deducts from amount at datetime chosen. Otherwise can't book.

Also considering doing this in Flask instead perhaps? Thoughts, Chris? Guessing you will be the one person to reply xD!

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,468 Points

I just might be.... It matters if the final UI will be web-based or not. If entirely web-based, not sure why tkinter would be needed. On the other hand, you can still use peewee to handle the backend for DB work then use tkinter as the front-end.

If you need to run this on more than one machine a time, then you'll need to coordinate the DB access, then running a local tkinter front-end makes less sense.

Coming full circle, even if it's only on a local machine, you can still use peewee to run the front end (as a local webserver). This way you'll be able to expand to a web-based solution asa the project grows.

It is always better to get a minimal viable product running first, than it is to sweat all the details up front. Try a simple proof of concept using peewee alone and peewee+tkinter to see which path seems best. It might have more to do with your user's experience than your coding preferences

Best of Luck!

Dates are always a bit of a pain whenever working with more than one system, but I think your best bet is stick with one date format (probably ISO-8601) and if you can, always in the same timezone (try convert everything to UTC).

Flask isn't necessarily going to make this any easier, it would just be used to make a web app instead of a GUI app like Tkinter.

You'd might want to look at using an ORM to handle the database-side of things so you don't have to do all the SQLite date functions in SQL.

If you decide to stick to Tkinter, try doing a search for tkinter datepicker, tkinter timepicker or tkinter calendar, etc.

Oh and here's a little GitHub repo that someone has put together to make a booking system with Python and SQLite:

OneScreenfulOfPython/booking-system

I was thinking about doing it in flask as I think doing the distributed system may be easier to make as I have more experience with it.

My end user luckily is very open to any solution, but I think I am gonna stick with tkinter and do it all that way and I like what you said Chris, It could just be used as a proof and I can change to web based later.

Thanks both of you, I like that Github repository Iain and I'm definitely going to check it out and a big thank you for the tkinter datetime stuff! It could end up saving me!

We'll see how it goes!

Just reading through github repository, it's pretty neat but it's using SQL and SQlite; wsgiref.util setup_testing_defaults, shift_path_info and wsgiref.simple_server make_server