Stylisez vos interfaces tkinter avec du CSS
Project description
TkCss
Stylisez vos interfaces tkinter avec du CSS.
Classes, IDs, :hover, :focus, fichiers .css externes — tout ce que vous aimez du web, dans votre app desktop.
Installation
pip install tkcss
Support JPEG/WebP (optionnel) :
pip install tkcss[images]
Démarrage rapide
from tkcss import Window, Text, Button
app = Window("Mon App", width=400, height=250, css="""
window { background-color: #1a1a2e; }
text { color: white; font-size: 18px; margin: 20px; }
button { background-color: #e94560; color: white; padding: 10px; }
button:hover { background-color: #c73652; }
""")
app.add(Text("Bienvenue !"))
app.add(Button("Démarrer", on_click=lambda: print("Cliqué !")))
app.center().run()
Fonctionnalités
- ✅ Sélecteurs — tag (
button), classe (.btn), ID (#submit), inline - ✅ Pseudo-classes —
:hoveret:focussimulés via les bindings tkinter - ✅ Fichiers
.cssexternes —Window(..., css_file="style.css") - ✅ 6 composants —
Window,Text,Button,Input,Frame,Image - ✅ Propriétés CSS — couleurs, polices, tailles, padding, margin, cursor, relief
- ✅ 0 dépendance — Pillow optionnel pour JPEG/WebP
- ✅ Python 3.8+
Composants
| Composant | Sélecteur CSS | Description |
|---|---|---|
Window |
window |
Fenêtre principale |
Text |
text |
Étiquette / texte |
Button |
button |
Bouton cliquable |
Input |
input |
Champ de saisie |
Frame |
frame |
Conteneur / carte |
Image |
image |
Affichage d'image |
Exemples
Sélecteurs classe & ID
from tkcss import Window, Button, Text
app = Window("Sélecteurs", width=350, height=200, css="""
.btn-primary { background-color: #e94560; color: white; padding: 10px; }
.btn-primary:hover { background-color: #c73652; }
#titre { color: #7b61ff; font-size: 18px; font-weight: bold; }
""")
app.add(Text("TkCss", css_id="titre"))
app.add(Button("Cliquer", css_class="btn-primary"))
app.center().run()
Formulaire de connexion
from tkcss import Window, Text, Button, Input, Frame
app = Window("Connexion", width=380, height=400, css="""
window { background-color: #0f0f23; }
.carte { background-color: #1a1a3e; padding: 20px; margin: 10px; }
input { background-color: #0f0f23; color: #ccd6f6; width: 240px;
border-width: 1; padding: 8px; margin: 6px; }
input:focus { background-color: #16163a; }
.btn { background-color: #e94560; color: white; font-weight: bold;
width: 150px; padding: 10px; margin: 10px; cursor: pointer; }
.btn:hover { background-color: #c73652; }
""")
email = Input(placeholder="Email")
mdp = Input(placeholder="Mot de passe", password=True)
carte = Frame(css_class="carte")
carte.add(email).add(mdp)
carte.add(Button("Se connecter", on_click=lambda: print(email.get()), css_class="btn"))
app.add(Text("Connexion", style={"color": "white", "font-size": "20px", "margin": "20px"}))
app.add(carte)
app.center().run()
Fichier .css externe
/* style.css */
window { background-color: #f8f9fa; }
text { color: #333; font-family: Helvetica; }
button { background-color: #28a745; color: white; padding: 8px; }
button:hover { background-color: #218838; }
from tkcss import Window, Text, Button
app = Window("App", width=400, height=300, css_file="style.css")
app.add(Text("Bonjour !"))
app.add(Button("Valider"))
app.center().run()
Propriétés CSS supportées
| Catégorie | Propriétés |
|---|---|
| Couleurs | color, background-color, background |
| Typographie | font-family, font-size, font-weight, font-style, text-decoration, text-align, wraplength |
| Dimensions | width, height, padding, margin, margin-top/bottom/left/right |
| Bordure | border-width, relief |
| Interaction | cursor, placeholder-color |
border-radius,box-shadow,opacity,transitionet les gradients ne sont pas supportés par tkinter et sont ignorés silencieusement.
Licence
MIT — Libre d'utilisation, modification et distribution.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tkcss-0.2.2.tar.gz.
File metadata
- Download URL: tkcss-0.2.2.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4981968c7fb770a9ef5b8556ee8cb27e5393a73c5380fc3170632d7d4544dfe
|
|
| MD5 |
d81172e10ead4e6dde8824debf7e7390
|
|
| BLAKE2b-256 |
d2f53edd877de52d72912a926fd2f1a683fb2be0d625cc84c1ee6c8c72d6cbde
|
File details
Details for the file tkcss-0.2.2-py3-none-any.whl.
File metadata
- Download URL: tkcss-0.2.2-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e68539a1051a2a358e8a18ea571513e5e56ec62f651eaf06e02ab3f27ee0f84f
|
|
| MD5 |
fffae5c6a0a7a6ec176dd59852640078
|
|
| BLAKE2b-256 |
ffc8f2bc87f362ff24f527af16d680fcfdc2a047f8dcaaa6add44a6da6465581
|