Giter VIP home page Giter VIP logo

Comments (9)

rdbende avatar rdbende commented on May 25, 2024 1

I'm currently not able to implement it, but I think it's a good starting point for you.

It's basically just adding a font parameter to the __init__, and a key to _keys, and Tukaans' widget API does the rest for you.
You can see, how other parameters are implemented in label.py, and textbox.py specifically for font attributes.

from tukaan.

Moosems avatar Moosems commented on May 25, 2024

I'm currently not able to implement it, but I think it's a good starting point for you.

It's basically just adding a font parameter to the __init__, and a key to _keys, and Tukaans' widget API does the rest for you. You can see, how other parameters are implemented in label.py, and textbox.py specifically for font attributes.

@rdbende I added it as:

"font": tuple,
...
font: tuple | None = None,
...
font=font,

But this gives the error:

File "/Users/Moosems/Desktop/tukaan/tukaan/widgets/button.py", line 44, in __init__
    BaseWidget.__init__(
  File "/Users/Moosems/Desktop/tukaan/tukaan/widgets/_base.py", line 316, in __init__
    Tcl.call(None, self._tcl_class, self._name, *Tcl.to_tcl_args(**kwargs))
  File "/Users/Moosems/Desktop/tukaan/tukaan/_tcl.py", line 174, in call
    raise TclError(msg) from None
tukaan.exceptions.TclError: unknown option "-font"

from tukaan.

rdbende avatar rdbende commented on May 25, 2024

tukaan.exceptions.TclError: unknown option "-font"

Nah, that is odd. I have to figure out why that happens, the manual page says that it works with Tk 8.5 and eith 8.6 as weel, so it shouldn't be an unknown option.

"font": tuple,
...
font: tuple | None = None,
...
font=font,

In my opinion, managing fonts in Tkinter is kinda inconvenient. You have to create tuples with some random str values, and just in the right order, and if you want to skip a property from that order, you have to use Tcl-like kwargs, and whatnot. Again, since explicit is better than implicit, Tukaan has a function, that generates this tuple for you, so you can simply use keyword arguments, and it will return a Tcl-compatible tuple. Its full signature is this: tuple[str | int | bool, ...].
The other thing that Tukaan has, is Font objects, that can be changed dinamically, so you can do

some_widget.font.bold = True

and it will change every associated widget's font to bold immediately. It's also possible to load a font from file woth them, so it gives you a lotta power.

As for _keys for the TextBox widget I defined the type as Font (the font object), but I forgot about the possibility to use the font() function. When using it, there's no Font object associated with the widget, so it can't really use that. Now I need to figure out, what should be that type, but you have to wait for that 😕.

{"font": ????}
...
font: Font | tuple[str | int | bool, ...] | None = None,  # You'll have to 'from tukaan.fonts import Font' first
...
font=font

from tukaan.

Moosems avatar Moosems commented on May 25, 2024

Personally I really love the way that tkinter handles fonts for the user but I would like it if you didn't always have to give a size value. Tkinter is super flexible when it comes to fonts but I would also love it where it sturdy. I honestly really dislike making font objects and normally use
normal_font=("Courier New bold", 15)

from tukaan.

Moosems avatar Moosems commented on May 25, 2024

@rdbende Any updates? I'm still hoping to fix this

from tukaan.

rdbende avatar rdbende commented on May 25, 2024

@rdbende I added it as:

"font": tuple,
...
font: tuple | None = None,
...
font=font,

But this gives the error:

File "/Users/Moosems/Desktop/tukaan/tukaan/widgets/button.py", line 44, in __init__
    BaseWidget.__init__(
  File "/Users/Moosems/Desktop/tukaan/tukaan/widgets/_base.py", line 316, in __init__
    Tcl.call(None, self._tcl_class, self._name, *Tcl.to_tcl_args(**kwargs))
  File "/Users/Moosems/Desktop/tukaan/tukaan/_tcl.py", line 174, in call
    raise TclError(msg) from None
tukaan.exceptions.TclError: unknown option "-font"

Actually, I successfully implemented this today in the same way, so Idk what was the problem.

from tukaan.

Moosems avatar Moosems commented on May 25, 2024

Can you create a release for me to test it with?

from tukaan.

rdbende avatar rdbende commented on May 25, 2024

Soon!

from tukaan.

Moosems avatar Moosems commented on May 25, 2024

😀

from tukaan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.