https://github.com/limafresh/tkinter-rounded-button
An unofficial rounded button for Tkinter toolkit
https://github.com/limafresh/tkinter-rounded-button
custom-widget custom-widgets rounded-button tkinter tkinter-button tkinter-rounded-button tkinter-widget tkinter-widgets
Last synced: about 1 month ago
JSON representation
An unofficial rounded button for Tkinter toolkit
- Host: GitHub
- URL: https://github.com/limafresh/tkinter-rounded-button
- Owner: limafresh
- License: unlicense
- Created: 2025-04-03T19:11:10.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2025-04-03T19:41:42.000Z (about 2 months ago)
- Last Synced: 2025-04-03T20:24:41.847Z (about 2 months ago)
- Topics: custom-widget, custom-widgets, rounded-button, tkinter, tkinter-button, tkinter-rounded-button, tkinter-widget, tkinter-widgets
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rounded button for Tkinter

Tkinter rounded button. An unofficial modern button for Tkinter that supports rounding.

## How to use?
It's very simple - download the `RoundedButton.py` file and place it in the folder where your script file is. Then import:```python
from RoundedButton import RoundedButton
```And create button, for example:
```python
button = RoundedButton(root, text="My button")
button.pack()
```## Arguments
| Argument | Description |
| ---------------- | ------------ |
| **width** | int value in px, for example, width=250 |
| **height** | int value in px, for example, height=50 |
| **text** | text for button |
| **font** | int (for example, font=20) or tuple (for example, font=("Arial", 20)) |
| **radius** | radius of rounding, int value |
| **bg_color** | button background color, for example bg_color="red" or bg_color="#f0f0f0" |
| **fg_color** | button text color |
| **command** | button command |
| **cursor** | button cursor, by default cursor="hand2" |## Methods
- `.config()`
- `.cget()`## Code example
### Simple example
```python
import tkinter
from RoundedButton import RoundedButtondef clickme():
clickme_button.config(text="Thanks!", bg_color="yellow", fg_color="black")root = tkinter.Tk()
root.geometry("200x200")
root.title("Simple example")clickme_button = RoundedButton(root, text="Click me!", command=clickme)
clickme_button.pack(padx=10, pady=10)quit_button = RoundedButton(root, text="Quit", bg_color="red", command=quit)
quit_button.pack(padx=10, pady=10)root.mainloop()
```### Calculator

```python
import tkinter as tk
from RoundedButton import RoundedButtondef press(key):
current = entry.get()
if key == "=":
try:
result = str(eval(current))
entry.delete(0, tk.END)
entry.insert(tk.END, result)
except Exception:
entry.delete(0, tk.END)
entry.insert(tk.END, "Error")
elif key == "C":
entry.delete(0, tk.END)
else:
entry.insert(tk.END, key)root = tk.Tk()
root.title("Calculator")
root["bg"] = "#2e2e2e"entry = tk.Entry(root, font=(None, 15), relief=tk.FLAT, justify=tk.RIGHT)
entry.pack(fill=tk.X, padx=5, pady=20)buttons_frame = tk.Frame(root, bg="#2e2e2e")
buttons_frame.pack()row, column = 0, 0
buttons = [
"7",
"8",
"9",
"+",
"4",
"5",
"6",
"-",
"1",
"2",
"3",
"*",
"C",
"0",
"=",
"/",
]for button_text in buttons:
button = RoundedButton(
buttons_frame,
width=50,
height=50,
radius=20,
text=button_text,
font=20,
command=lambda key=button_text: press(key),
)
button.grid(row=row, column=column, padx=5, pady=5)if button_text in ["+", "-", "*", "/"]:
button.config(bg_color="orange")
elif button_text == "=":
button.config(bg_color="blue")
else:
button.config(bg_color="#6e6e6e")column += 1
if column == 4:
column = 0
row += 1root.mainloop()
```