Closed ghost closed 4 years ago
Hi @Whearly - glad you're enjoying using appJar.
There is an example of how to set the font on the page you mention: http://appjar.info/pythonGuiOptions/#font
app.setFont(size=16, family="Times", underline=True, slant="italic")
app.setButtonFont(size=14, family="Verdana", underline=False, slant="roman")
And it seems to work fine on my platform.
@Whearly - I've been thinking about this a bit more and have come up with the following...
First create your stylesheet, called myStyle.py
:
body = {
'geom':'400x400',
'font':{'size':33, 'family':"helvetica", 'weight':'normal', 'underline':False, 'slant':"roman", 'overstrike':False},
'bg':'yellow',
'fg':'red'
}
t1 = {
'font':{'size':16, 'family':"times", 'weight':'normal', 'underline':False, 'slant':"italic", 'overstrike':True},
'bg':'red',
'fg':'pink'
}
t2 = {
'font':{'size':20, 'family':"times", 'weight':'normal', 'underline':False, 'slant':"italic", 'overstrike':True},
'bg':'green',
'fg':'orange'
}
t3 = {
'font':{'size':24, 'family':"times", 'weight':'bold', 'underline':True, 'slant':"roman", 'overstrike':False},
'bg':'blue',
'fg':'green'
}
t4 = {
'font':{'size':28, 'family':"times", 'weight':'bold', 'underline':True, 'slant':"roman", 'overstrike':False},
'bg':'yellow',
'fg':'blue'
}
Then, use it in your code:
from appJar import gui
import myStyle as style
with gui("appjar font problem", **style.body) as app:
app.label("l1", "Label 1")
app.label("l2", "Label 2")
app.label("l3", "Label 3", **style.t1)
app.label("l4", "Label 4", **style.t2)
app.label("l5", "Label 5", **style.t3)
app.label("l6", "Label 6", **style.t4)
app.label("l7", "Label 7")
The myStyle.py
file looks similar to a css file, except for all the extra quotation marks.
We then just unpack the style in the call to add labels.
I might look into making this a feature of a future release - appJar can auto look for a style file, and then have a specific parameter for style ids...
Closing this, as happy with the current implementation.
Is there a way to set font family and other stylings by class (as in CSS class) to avoid repetitious coding on each widget? As far as I can tell, I will have to set font family on each widget separately to avoid error messages and have already set all the other styles separately. It would be great if I could assign a class to a widget and then define the class once like in CSS. Thanks for the awesome GUI maker, I am in 7th heaven using appJar, finally able to make a front end for a sqlite db (I hope) without going to coder school for years. The reason I'm not able to set font globally (without error messages) is demonstrated below.
Setting font family works but this error appears in the console every time I run a program in which I've set font family.