Welcome folks today in this blog post we will be generating
random facts using randfacts library in python. All the full source code of application is given below.
In order to get started you need to install the following library using the
pip command as shown below
pip install randfacts
After installing the library you need to make an
app.py file and copy paste the following code
# import required modules import tkinter as tk from tkinter import * import randfacts import time # function to add facts def move(): facts = randfacts.getFact(True) c = "*)" label = Label(root, text=c+facts) label.pack() # function to close window def destroy(): root.destroy() # driver code root = tk.Tk() # adjust window root.config(bg="red") root.geometry("400x400") # add buttons button = tk.Button(root, text="Click here for Facts", command=move) button2 = tk.Button(root, text="Clear and quit", command=destroy) button.pack() button2.pack() root.mainloop()
Now if you execute the
python script by typing the below command as shown below
As you can see when you click the
button to generate random facts then the random facts is generated in the desktop app.