-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ken-morel/dev
Improved Templating and Writeable Engines
- Loading branch information
Showing
92 changed files
with
10,931 additions
and
28,731 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +0,0 @@ | ||
# taktk | ||
|
||
taktk from from the [bulu](https://wikipedia.com/wiki/bulu) word | ||
_tak_, meaning to order, and _tk_ for `tkinter`. | ||
|
||
taktk aims to give you a more orderly, easy and responsive way to build tkinter | ||
pages. | ||
It is currently in build(since last 2 days), but I will expose on what it can | ||
do now. | ||
|
||
## hello world example | ||
|
||
Here the example in [examples/simple.py](examples/simple.py) | ||
|
||
```python | ||
from tkinter import Tk | ||
from taktk.component import Component | ||
|
||
|
||
class Comp(Component): | ||
"""\ | ||
\\frame | ||
\\frame pos:grid=0,0 padding=5 | ||
\\label text={label_text} pos:grid=0,0 | ||
\\button text='close >' command={close} pos:grid=1,0 | ||
\\frame pos:grid=0,1 padding=5 relief='sunken' | ||
\\label text={{number}} pos:grid=0,0 | ||
\\ctk.button text='add +' command={add} pos:grid=1,0""" | ||
code = __doc__ | ||
|
||
label_text = 'close the window' | ||
number = 0 | ||
|
||
def close(self): | ||
root.destroy() | ||
print("closed") | ||
|
||
def add(self): | ||
self['number'] += 1 | ||
self.update() | ||
|
||
|
||
root = Tk() | ||
|
||
component = Comp() | ||
component.render(root).grid(column=0, row=0) | ||
|
||
root.mainloop() | ||
``` | ||
|
||
![demo](images/example-simple.png) | ||
|
||
> [!WARNING] | ||
> The component building language is still in development and may be extremely | ||
> strict | ||
|
||
## Example 2: A todo list | ||
|
||
```python | ||
r""" | ||
\frame | ||
\ctk.frame pos:grid=0,0 width=350 pos:sticky='nsew' | ||
\ctk.entry width=300 pos:grid=0,0 text={{entry}} pos:xweight=2 | ||
\button text='+' command={add_todo} pos:grid=1,0 pos:xweight=0 | ||
\ctk.frame pos:grid=0,1 width=350 pos:sticky='nsew' | ||
!enum todos:(i, todo) | ||
\ctk.label text={str(i + 1) + ') ' + todo } pos:grid={(0, i)} pos:sticky='nsw' bind:1={popper(i)} | ||
# popper closure does popping for you | ||
""" | ||
from tkinter import Tk | ||
from taktk.component import Component | ||
|
||
|
||
class Todo(Component): | ||
code = __doc__ | ||
|
||
todos = [] | ||
entry = "Enter todo here" | ||
|
||
def close(self): | ||
root.destroy() | ||
|
||
def add_todo(self): | ||
self.todos.append(self['entry']) | ||
self.entry = "" | ||
self.update() | ||
|
||
def clear(self): | ||
self.todos.clear() | ||
self.update() | ||
|
||
def popper(self, idx): | ||
def func(e): | ||
self.todos.pop(idx) | ||
self.update() | ||
return func | ||
|
||
|
||
root = Tk() | ||
root.title('Todo list') | ||
|
||
editor = Todo() | ||
editor.render(root).grid(column=0, row=0) | ||
|
||
root.mainloop() | ||
``` | ||
|
||
![demo](images/example-todo.png) | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from contextlib import contextmanager | ||
from tkinter import * | ||
from tkinter.ttk import * | ||
|
||
import win32con | ||
import win32gui | ||
from PIL import Image, ImageFilter, ImageGrab, ImageTk | ||
from ttkbootstrap import Window | ||
|
||
|
||
def capture_screen_excluding_window(window): | ||
"""Capture the entire screen, excluding the given window""" | ||
hwnd = window.winfo_id() | ||
x0, y0, x1, y1 = ( | ||
window.winfo_rootx(), | ||
window.winfo_rooty(), | ||
window.winfo_rootx() + window.winfo_width(), | ||
window.winfo_rooty() + window.winfo_height(), | ||
) | ||
screen_width, screen_height = ( | ||
window.winfo_screenwidth(), | ||
window.winfo_screenheight(), | ||
) | ||
with transparent(window): | ||
img = ImageGrab.grab(bbox=(x0, y0, x1, y1)) | ||
img_blurred = img.filter(ImageFilter.GaussianBlur(radius=10)) | ||
img_tk = ImageTk.PhotoImage(img_blurred) | ||
return img_tk | ||
|
||
|
||
@contextmanager | ||
def transparent(win, alpha=0.3): | ||
win.attributes("-alpha", alpha) | ||
yield | ||
win.attributes("-alpha", 1) | ||
|
||
|
||
root = Window(themename="superhero") | ||
root.attributes("-transparentcolor", "#555") | ||
root.geometry("500x300") | ||
|
||
root.style.configure( | ||
"Transparent.TFrame", | ||
bg="#555", | ||
) | ||
frm = Frame(root, style="Transparent.TFrame", bootstyle=None) | ||
label = Label(frm) | ||
label.pack(fill="both", expand=True) | ||
frm.pack(fill="both", expand=True) | ||
|
||
|
||
def capture_and_display(): | ||
img_tk = capture_screen_excluding_window(root) | ||
label.config(image=img_tk) | ||
label.image = img_tk # keep a reference to the image | ||
|
||
|
||
# Create a button to capture and display the screen | ||
btn = Button(root, text="Capture", command=capture_and_display) | ||
btn.pack() | ||
|
||
|
||
root.mainloop() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.