w3resource

Python tkinter Basic Exercise: Create a label and change the label font style using tkinter module

Python tkinter Basic: Exercise-3 with Solution

Write a Python GUI program to create a label and change the label font style (font name, bold, size) using tkinter module.

Sample Solution:

Python Code:

import tkinter as tk
parent = tk.Tk()
parent.title("-Welcome to Python tkinter Basic exercises-")
my_label = tk.Label(parent, text="Hello", font=("Arial Bold", 70))
my_label.grid(column=0, row=0)
parent.mainloop()

Sample Output:

Flowchart: Create a label and change the label font style (font name, bold, size) using tkinter module

Flowchart:

Flowchart: Create a label and change the label font style (font name, bold, size) using tkinter module

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python GUI program to import tkinter package and create a window. Set its title and add a label to the window.
Next: Write a Python GUI program to create a window and set the default window size using tkinter module.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz


Python: Tips of the Day

Maps the values of a list to a dictionary using a function, where the key-value pairs consist of the original value as the key and the result of the function as the value:

Example:

def tips_map_dictionary(itr, fn):
  ret = {}
  for a in itr:
    ret[a] = fn(a)
  return ret
print(tips_map_dictionary([2,4,6], lambda a: a * a))

Output:

{2: 4, 4: 16, 6: 36}