current position:Home>wxPython wx. Correction of font class · Wx Font tutorial

wxPython wx. Correction of font class · Wx Font tutorial

2022-05-15 03:52:41__ Program meow__

Preface ——Font class

wx.Font Class in order to set the font of the control , essential . However , about Font There are many tutorials on font classes , But for a long time . current wxPython Of Font Some parameters of the class have also been changed , It's different . And the tutorial mentioned in wxPython Although it can still be used in , But in IDE Cannot be detected in , Basic red . and , In the tutorial mentioned above, because there is no connection with wxPython Simultaneous updating , Less than half of the style . This article will explain in detail , Correct the mistake .
Show me an outdated construction ……

What is shown above is an article 2017 It's been a long time . Other descriptions are mostly similar to this . What this article will show is different from this kind , The latest standards adopted , And wxPython by 4.1.1 .
Of course , It can also be in wxPython Official help documents wx.Font .

Font Construction and use

Font There are many structures , But there are only two commonly used :

  • Font(fontInfo)
  • Font(pointSize, family, style, weight, underline=False, faceName="", encoding=FONTENCODING_DEFAULT)

Most of the tutorials you can see now except for the official side are the second ( As shown in the picture above ). The problem is family style weight The values of the three parameters . Here I will introduce both structures . Other construction methods are :

  • Font()
  • Font(font)
  • Font(pixelSize, family, style, weight, underline=False, faceName="", encoding=FONTENCODING_DEFAULT)
  • Font(nativeInfoString)
  • Font(nativeInfo)

These construction methods can be found on the official website wx.Font Study on your own , No more details here .

Construction one Font(fontInfo)

In this way, only one parameter needs to be passed fontInfo , And this parameter is a FontInfo class . Understanding this structure naturally becomes understanding FontInfo . Here is FontInfo One of the structures of .
FontInfo(pointSize)
Of course , There's another way FontInfo(pixelSize) , hold pointSize Changed to pixelSize .

Continue for FontInfo(pointSize) Explain the structure of .
This parameter pointSize Naturally, it's text size , by float Floating point objects .

Method

FontInfo The method and its function are as follows .

  • Bold(bold=True): Set bold style for words
  • Light(light=True): Set a thinner style for words
  • wait ……

There's basically no need to enumerate them all , After all, construct two is more commonly used , The functions are generally more complete . The detailed explanation is in the structure II below .

Example

from wx import *

font = Font(FontInfo(10).Bold().Underline())

The above use constructs an example created , namely , Created a text size ( pointSize ) by 10 Bold and underlined Fonts .

Structure II

This is Font One of the most commonly used settings , So there will be a detailed explanation below .
Font(pointSize, family, style, weight, underline=False, faceName="", encoding=FONTENCODING_DEFAULT)

  • pointSize : Text size :float
  • family : HTTP: :FontFamily
  • style : Writing style :FontStyle
  • weight : The text is thick and thin :FontWeight
  • underline : Whether to underline :bool
  • faceName : Font name :string
  • encoding : Text encoding :FontEncoding

among , FontFamily 、 FontStyle 、 FontWeight 、 FontEncoding yes wxPython Built in style . Here's a description .

FontFamily

  • FONTFAMILY_DEFAULT : default font
  • FONTFAMILY_DECORATIVE : Decorative Fonts
  • FONTFAMILY_ROMAN : Serif font
  • FONTFAMILY_SCRIPT : Handwriting
  • FONTFAMILY_SWISS : Sans serif fonts
  • FONTFAMILY_MODERN : Isometric font
  • FONTFAMILY_TELETYPE : Typewriter font

FontStyle

  • FONTSTYLE_NORMAL : Ordinary , No tilt
  • FONTSTYLE_ITALIC :( Italy ) Italics
  • FONTSTYLE_SLANT :( The Roman ) Italics

FontWeight

  • FONTWEIGHT_THIN : The thinnest font
  • FONTWEIGHT_EXTRALIGHT : Very fine font
  • FONTWEIGHT_LIGHT : Fine body
  • FONTWEIGHT_NORMAL : Normal word weight
  • FONTWEIGHT_MEDIUM : Medium word weight ( Than FONTWEIGHT_NORMAL Slightly thick )
  • FONTWEIGHT_SEMIBOLD : Slightly bold font
  • FONTWEIGHT_BOLD : bold
  • FONTWEIGHT_EXTRABOLD : Bold font
  • FONTWEIGHT_HEAVY : Very thick font
  • FONTWEIGHT_EXTRAHEAVY : The thickest font

FontEncoding

FontEncoding There are many kinds of , Here, only limited codes are explained , The rest are listed directly

  • FONTENCODING_SYSTEM : System default code
  • FONTENCODING_DEFAULT : Apply default encoding
  • FONTENCODING_ISO8859_1
  • FONTENCODING_ISO8859_2
  • FONTENCODING_ISO8859_3
  • FONTENCODING_ISO8859_4
  • FONTENCODING_ISO8859_5
  • FONTENCODING_ISO8859_6
  • FONTENCODING_ISO8859_7
  • FONTENCODING_ISO8859_8
  • FONTENCODING_ISO8859_9
  • FONTENCODING_ISO8859_10
  • FONTENCODING_ISO8859_11
  • FONTENCODING_ISO8859_12
  • FONTENCODING_ISO8859_13
  • FONTENCODING_ISO8859_14
  • FONTENCODING_ISO8859_15
  • FONTENCODING_KOI8
  • FONTENCODING_KOI8_U
  • FONTENCODING_ALTERNATIVE
  • FONTENCODING_BULGARIAN
  • FONTENCODING_CP437
  • FONTENCODING_CP850
  • FONTENCODING_CP852
  • ……
  • ……

Too many encoding methods , There must be no room for .wx.FontEncoding You can check .

Postscript

So this article is for wx.Font This is the end of the class correction and tutorial . The corrected part is mainly reflected in the description of four enumerations . Want to learn more wxPython knowledge , Welcome to the column wxPython ~

copyright notice
author[__ Program meow__],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/131/202205111509089916.html

Random recommended