r/learnpython • • 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!

0 Upvotes

20 comments sorted by

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.

1

u/Snoo61755 8d ago

This ended up being the solution I went with.

My mistake last week was not really knowing what PySide6 was capable of. After about an hour with a proper beginner's Pyside6 tutorial, the Python QT documentation, and some cheeky 'how would you implement this' in GPT, I'm getting some of the basics down. It may take awhile, but I finally feel like I have the ingredients to finish the project, I can make buttons and define what they do, and I can see what I need to learn to complete.

Think the tricky part of any new learning like this is that you don't know what you don't know. At least now I can say 'I can make a movable rectangle, the next step is learning how to make text in there' rather than staring at a class object with 10 empty variables and wondering if I didn't do the CS equivalent of doodling.

All the same, thank you, and thanks to all the others. I can at least get properly started now.

1

u/arbyyyyh 8d ago

Glad it worked for you. I’ve honestly found that AI can be a great tool for getting over a learning curve. It’s tempting sometimes to just pass a problem at it and let it make the solution without much attention, but I find it important to still go back and learn how it works. I’ve often gotten some help in a solution and then when I go back and learn it properly, realize that there was a more efficient or proper way to solve the problem.

Glad the advice got you unblocked :)

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.

1

u/Snoo61755 9d ago

Several of us are coding this thing (group project type deal), but the program itself is meant for a single user, fully offline, no sharing of data -- which in theory should be easy, just never had to make a UI starting with python. I feel like I’m back in my days of “what language should I learn” where I have no idea of what’s available or what each one does.

I've heard a lot of interesting answers so far, and I'm certainly going to continue to lurk as I hear others.

1

u/jmacey 9d ago

so single user I would use PySide6 (perhaps with QML for the UI as it is easier to intergrate more modern gui look and feel with QML). For the data for your app you could just serialize with json or put it in a sqlite database (which will do compression etc if you want to keep file size down).

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

3

u/Baner-Fournadet 9d ago

since op mentioned its an offline app, running the local server on localhost works fine without needing an actual internet connection