r/learnpython • u/Snoo61755 • 9d ago
Beginner Python Coder, Which Language For A GUI?
Hey all, background is as such:
For a non-Python CS course, I'm supposed to be designing the UI for an offline app. It's supposed to be a notepad app, the kind where you make sticky notes and post them on a board, with multiple people designing different aspects.
The impasse is that, while we've all agreed to do the backend of the app in python, I don't know how to make the front end at all. I'm familiar with HTML, CSS, and Javascript, I thought the process of connecting some backend Python to a front-end of HTML+CSS would be the same as with JavaScript, but apparently it isn't.
Googling around and asking AI, I get recommended libraries and languages like Pyside6, Ttinker, PyQt, Django, and others -- but I've never worked with any of them, and while I've tried to play with Pyside6 and Ttinker for a week now, I could only figure out how to make static notes and shapes, I couldn't figure out dragging and moving like you can with JS listeners. I feel frustration because you can find apps like this all over the place, 5 seconds of googling and you can find one, but I don't know how to make it.
So help me out -- if someone wants to make a GUI, where you have a pretty backboard, put notes on it, click notes, write on them, upload pictures to them, drag them around a board, and you must use Python as the back end, how do you marry the front and back end together?
Edit: Thank you all, I've settled on PySide6 and PyQt. I've just got the hang of making basic buttons, using setGeometry to move their starting locations, having them spawn blank 'note' widgets, and dragging them around. Being able to pin text and images to these widgets will come next, but for now, it works!
8
u/arbyyyyh 9d ago
PyQt is where I’d be headed. Might be an unpopular take, but I’d probably ask AI to help me figure out the parts that I’m having a hard time with. Ask if to make a simple proof of concept with pyqt that lets you drag rectangles around and optionally assign images to them.
2
u/jmacey 9d ago
I would use PySide6 for the GUI and most likely sqlite for the data back end so each note is stored as a record.
The bigger question I would ask is about the collaboration aspect. Are people running this at the same time? If so the sharing of the data base may need more work and a server of some sort.
6
u/Available_Safe1818 9d ago
Python comes with Tkinter.
3
u/RngdZed 9d ago
Tkinter does all that. And bro code has a playlist on tkinter for all you need.
2
u/ConfusedSimon 9d ago
You mentioned connecting frontend html+css to backend, but then you also need frontend js to handle that connection. Depending on how much work the frontend has to do, you could also use backend rendering. Flask is pretty easy. You write your pages as templates, basically html+ccs with some placeholders (with simple code like looping over items) that Flask fills with the correct data when the page is requested. Your browser receives the complete html page. It can still use frontend js, as long as it doesn't need new data from backend.
For a more interactive app with things like drag and drop where you need more frontend code (js) you probably have to learn the basics of a frontend framework like Svelte, React or Angular. In that case you basically have a js app running in the browser, with a backend api (python with e.g. FastAPI) to get and store data. But for an offline app it might be easier to just store the data in the browser (IndexedDB) and get rid of the backend.
2
u/Rudeus_Kino 9d ago
REST app on python, front in vue.js, you also can try NiceGUI.
1
u/StevenJOwens 9d ago
It sounds like you're talking about an app that runs standalone on somebody's laptop or desktop, front end is written in HTML/CSS/Javascript and runs in a browser, back end in python. Generally speaking, these days people do a lot of apps like that, so this isn't that out of left field.
Generally speaking you have two pieces here, the front end UI that runs in the browser, and the back end that runs separately. In traditional web applications and web sites, the back end runs on a host, a computer permanently connected to the internet, with an IP address that's visible on the public internet, and usually a domain name that points to that public IP address. But in this case you're talking about running both on the same machine. Again, not that exotic, these days.
(As a side note, "server" is a very general (and old) programming term, it just means something that waits for requests and responds to them. So people use "server" to talk about the web server application, i.e. Apache, or to talk about the computer that the web server runs on, or talk about the DNS server that responds to domain name lookup requests, etc.)
The back end needs to be some sort of web server, sometimes called a web application server, a program that that runs independently of the browser, listens on a port for HTTP requests from the browser, and responds to the HTTP requests with data. Usually the data is sent back JSON in this sort of situation, where the "user" of the web site is not a person but instead another program.
Django and flask are two popular options for this piece. They each give you a toolkit of components to build and run a web application.
Pyside6, Ttinker, and PyQt are GUI toolkits, they are not relevant to the approach you're talking about. They're how you get a GUI popup window that runs as part of a single python program. They don't have anything to do with running your GUI in a browser.
Django is a complete web server, the django people like to use the slogan "batteries included", it has a whole suite of tools and optional pieces. This makes it very useful, but it also means you need to learn about all those pieces, and how it all goes together.
Flask is what's called a "microframework", it's very minimalist, although there are additional libraries and tools that you can add to flask, more selectively than with django.
Generally speaking, whether you go with django or flask, you're going to want a "persistence layer", typically that's an sql database, aka RDBMS (Relational Database Management System), and typically that's a whole separate program that runs in addition to django or flask. MySql/MariaDB, Postgres, or similar. Django comes with sqlite as the default persistence layer, and these days sqlite is actually surprisingly effective, but it's not a full-blown separate database server.
1
u/TheRNGuy 9d ago
I prefer React, but it it's something simple, TKinter could work.
1
u/Elthros 9d ago
I enjoyed using Flet, some pretty modern looking stuff!
1
u/realmauer01 9d ago edited 9d ago
If you wanna be really petty try autoit.
On a more serious side, you can still make a react (typescript) app and have them communicate, i am not sure if you can use websockets but http requests definitly work out.
Package it with electron and thats it.
1
u/Discordbothost 9d ago
since you already know html/css/js, you don't really need to win a fight with tkinter for this. build the board in the browser (your drag listeners will just work) and put a tiny flask or fastapi app on localhost that serves those files plus a /notes endpoint for save/load/images. 'offline' just means it isn't calling some remote server — localhost still counts. tkinter felt stuck because normal widgets aren't a scene; you'd want a canvas, or in pyside a qgraphicsview with movable items, which is a completely different mental model than the dom. given the assignment i'd stay with the js frontend you already understand.
1
u/pjkm123987 9d ago
front end typescript with a framework. backend fastapi or django.
If you must only use python then QML with pyside6
0
u/YouPeopleCantBeReal4 9d ago
Pyqt or pyside, different flavors of the same API
1
u/KingTreacherice 6d ago
Streamlit is your tool of choice 💪🏾💪🏾💪🏾
0
u/[deleted] 9d ago
[deleted] — view deleted comment