Python Tkinter Example – Truth or Dare Game

Python Tkinter Example – Truth or Dare Game

Building a Python Truth or Dare Game with Tkinter

 

Although it’s a comical application, this serves as very good practice for using the native Tkinter system python has. 

If you’ve never worked with the Python user interface system then this an excellent code along for you.

Below is the full code for the Python Tkinter Example.

 

The full code used in the video is here:

import tkinter as tk
from random import *
import datetime

now = datetime.datetime.now()
seed(now)

dares = ["Watch another video",
"Subscribe to the channel",
"Like this video",]

truths = ["Was this tutorial easy to follow?",
"Did you learn something new about Python?",
"Why aren't you subscribed to the channel?",]

def dare():
    dareoutput = choice(dares)
    print(dareoutput)

def truth():
    truthoutput = choice(truths)
    print(truthoutput)

root = tk.Tk()
frame = tk.Frame(root)
frame.pack()

button = tk.Button(frame,
                   text="Truth",
                   fg="red",
                   command=truth)
button.pack(side=tk.LEFT)
DareButton = tk.Button(frame,
                   text="Dare",
                   command=dare)
DareButton.pack(side=tk.LEFT)

root.mainloop()

 

The Dares and Truths can be changed by changing the variables ‘truths’ and ‘dares’ to whatever values you like.

The code above can also be found on my github here.

Let me know what you think on my Youtube video comments? Also if you have any suggestions on what scripts you would like to see next feel free to let me know there as well!

Leave a Reply

Your email address will not be published. Required fields are marked *