0

How to use 2 different fonts in the same Label?

For txt1 one font and txt2 another different font

IE: Label(container_frame3, text=txt1+txt2,width=14)

j_4321
  • 15,431
  • 3
  • 34
  • 61
  • 2
    I don't think so. Could you maybe use a Text widget instead? – figbeam Mar 09 '21 at 21:24
  • 1
    Why don't you use two labels with different fonts instead? – acw1668 Mar 10 '21 at 07:29
  • 1
    No, that's not possible. If you want to mix fonts, you should use a Text widget instead of a Label. You can set the background to your widget background and omit the border, so it will look exactly like a label. You may even make it immutable by setting the state to DISABLED. So, it will look and feel like a label but you can mix any number of fonts by using tags. – Martin Wettstein Mar 10 '21 at 17:07

1 Answers1

0

I solved my problem using this : enter link description here

from tkinter import *
from tkinter.font import Font


root = Tk()
root.title('Example 2 fonts')
root.geometry('{}x{}'.format(300, 300))

#Fonts 
big_font = Font(family='Helvetica', size=12, weight='bold')
small_font = Font(family='Helvetica', size=8)


container_frame3= Frame(root, highlightbackground="gray80", highlightcolor="gray80", highlightthickness=1,bd=0,bg='red')
container_frame3.grid(row=0,sticky="nsew")

datalabel= Label(container_frame3, text="{}".format('21.15 %\n\n'),width=12,font=big_font,justify=CENTER,bg='blue')
datalabel.grid(row=0, column=0)
datalabel= Label(container_frame3, text='Mbps', font=small_font)
datalabel.grid(row=0, column=0)


root.mainloop()

that results in :solve

Now I have he problem to put that info in the middle of the frame I used sticky='w' But doesnt work