Python 3 Random Facts Generator GUI Desktop App Using Randfacts Library Full Project For Beginners

Python 3 Random Facts Generator GUI Desktop App Using Randfacts Library Full Project For Beginners

 

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.

 

 

Get Started

 

 

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

 

app.py

 

# 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()

 

See also  Python 3 Script to Build StringCase Converter (Camel case, Pascal case, Snake case) Using stringcase Library Full Project For Beginners

 

Now if you execute the python script by typing the below command as shown below

 

python app.py

 

 

As you can see when you click the button to generate random facts then the random facts is generated in the desktop app.

Leave a Reply