In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to use Scale controls to control the size and color of label fonts". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The numeric range control Scale can be used to resize numeric values.
First, prepare a list of various information and generate fonts.
# font setting.font_size = 12font_family = ['Times','Arial',' Roma'] font_weight = ['bold',' normal'] font_slant = ['italic','roman','normal']
# create fontlabel_font = Font (family=font_family [0], size=font_size, weight=font_weight [0], slant=font_slant [0]) use the font generated above to build a demo object tag: # create a label to display message.label = Label (root, text='ScaleTest', font=label_font, foreground= "# 000000",) label.grid (row=0, column=0, columnspan=4, sticky=E + W) to build Checkbutton controls that toggle underscores and delete lines:
# toggle underline.def toggle_underline (): under_line = label_font.cget ('underline') label_font.config (underline=not under_line) # create check button.ub = Checkbutton (root,text= "Underline", command=toggle_underline) ub.grid (row=1, column=0, columnspan=2) # toggle overstrike.def toggle_overstrike (): over_strike = label_font.cget (' overstrike') label_font.config (overstrike=not over_strike) # create check button.ob = Checkbutton (root,text= "Overstrike" Command=toggle_overstrike) ob.grid (row=1, column=1, columnspan=2)
Build Spinbox controls that adjust font and weight.
# label of readonly spinbox.Label (root, text='Family') .grid (row=2,column=0, sticky=E) def family_changed (): label_font.config (family=fb.get ()) # create a value spinbox.fb = Spinbox (root, values=font_family, wrap=True, state='readonly', command=family_changed) fb.grid (row=2,column= 1, columnspan=2, sticky=W+E)
# label of weight spinbox.Label (root, text='Weight') .grid (row=3,column=0, sticky=E) def weight_changed (): label_font.config (weight=wb.get ()) # create a weight spinbox.wb = Spinbox (root, values=font_weight, wrap=True, state='readonly', command=weight_changed) wb.grid (row=3,column= 1, columnspan=3, sticky=W+E)
So far, it's all explained before, and then there's the protagonist Scale control.
# create a lable of size scale.Label (root, text='Size') .grid (row=4,column=0, sticky=E)
Def scale_changed (value): label_font.config (size=value)
# create font size scale.fs = Scale (root, relief=GROOVE, orient=HORIZONTAL, from_=10, to_=32, resolution=1, command=scale_changed) fs.grid (row=4, column=1, columnspan=3, sticky=W+E)
The function that handles the drag event has an argument to pass the current value of the Scale control. With this parameter, you don't have to get it from the control. This process is used to set the font size, and the result is reflected directly on the label control.
# create a lable of gray scale.Label (root, text='Gray') .grid (row=5,column=0, sticky=E)
Def gray_changed (value): value ='{: 02x} '.format (int (value)) value =' #'+ value+value+value label.config (foreground=value) # create gray scale.cs = Scale (root, relief=GROOVE, orient=HORIZONTAL, from_=0, to_=255, resolution=1, command=gray_changed) cs.grid (row=5, column=1, columnspan=3, sticky=W+E)
The color adjustment process is basically the same as the font size, except that the color is generated using string formatting and merging.
This is the end of "how to use the Scale control to control the size and color of label fonts". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.