Question

In: Computer Science

PYTHON PROGRAMMING Using tktinker, create a gui that surrounds the code below that has buttons and...

PYTHON PROGRAMMING

Using tktinker, create a gui that surrounds the code below that has buttons and labels and an overall theme.

# Meet the chatbot Eve
print('Hi there! Welcome to the ChatBot station. I am going to ask you a series of questions and all you have to do is answer!')
print(' ')
print('Lets get started')

#begin questions

firstName = input('What is your first name?: ')
lastName = input('What is your last name? ')

print("Hi there, ", firstName + lastName, "nice to meet you")
print(" ")

# questions about users favorite things
currentYear = 2020
birthDay = input('What is the year were you born?: ')
birthDay = int(birthDay)
print('Wow! You are already', currentYear - birthDay)
print(" ")

# questions about favorite hobbies
firstHobby = input('Do you play any sports? ')
if(firstHobby == 'Yes'):
    sport = input('What sport do you play? ')
    print("Nice! I played Soccer and Tennis back when I was human")
    print(" ")
else:
    print("Bummer, I always liked sports")
    print(" ")

favAnimal = input('What is your favorite animal? ')
print("Oooohhh what a cool animal! My favorite is the red panda, such a unique and cute species!")
print(" ")

favSeason = input('What is your favorite season? ')
if(favSeason == 'Fall'):
    print("Wow! That is my favorite season also! The colors of the leaves are amazing")
    print(" ")
else:
    print("Nice! My favorite season is Fall!")
    print(" ")

siblings = input('Do you have any siblings in your family? ')
if(siblings == 'Yes'):
    print("Very nice, back when I was born a human I grew up with a sister")
    print(" ")
else:
    print("An only child I see")
    print(" ")

stateBorn = input('What state were you born in? ')
if(stateBorn == 'West Virginia'):
    print("My creator is also from there!")
    print(" ")
else:
    print("What a lovely state")
    print(" ")

#end questions

print("Well I thank you for your time but that is all the time we have, thank you for joining me today")






Solutions

Expert Solution

Programmed using PyCharm, After each entry press 'Enter Button'.

Code:

from tkinter import *

window=Tk() # Initialize tkinter window
window.title("ChatBot") # Title of the window
window.geometry("480x900") # Geometry of the Window

displayState = 1 # Initialize displaystate

def onClick(): # Onclick Function
    global displayState # Declare variable as global
    if displayState == 1: # If displayState is 1
        window.first = e1.get() # Get Values from e1 entry
        window.last = e2.get() # Get Values from e2 entry
        label5 = Label(window, text=f"Hi there,{window.first} {window.last}, nice to meet you", font="times 12").place(x=5, y=175) # Label
        label6 = Label(window, text="What is the year were you born?", font="times 12").place(x=5, y=200) # Label
        window.e3 = Entry(window, width=25) # Entry window
        window.e3.place(x=5, y=225) # Placement of entry box

    elif displayState == 2:
        year = window.e3.get() # Get Values from e3 entry
        currentYear = 2020 # Set Value of currentYear
        age = currentYear - int(year) # Calculate Age
        label7 = Label(window, text=f"Wow! You are already', {age}", font="times 12").place(x=5, y=250) # Label
        label8 = Label(window, text="Do you play any sports?", font="times 12").place(x=5, y=275) # Label
        window.e4 = Entry(window, width=25) # Entry window
        window.e4.place(x=5, y=300) # Placement of entry box

    elif displayState == 3:
        sport = window.e4.get() # Get Values from e4 entry
        if sport == 'Yes' or sport == 'yes': # If sport is yes
            label9 = Label(window, text="What sport do you play??", font="times 12").place(x=5, y=325) # Label
            e5 = Entry(window, width=25) # Entry window
            e5.place(x=5, y=350) # Placement of entry box
            window.cl = 1 # set value of variable
        elif sport == 'No' or sport == 'no': # If sport is no
            label9 = Label(window, text="Bummer, I always liked sports", font="times 12").place(x=5, y=325) # Label
            label11 = Label(window, text="What is your favorite animal?", font="times 12").place(x=5, y=350) # Label
            window.e6 = Entry(window, width=25) # Entry window
            window.e6.place(x=5, y=375) # Placement of entry box
            window.cl = 0 # set value of variable

    elif displayState == 4:
        if window.cl == 1:
            label10 = Label(window, text="Nice! I played Soccer and Tennis back when I was human", font="times 12").place(x=5, y=375) # Label
            label11 = Label(window, text="What is your favorite animal?", font="times 12").place(x=5, y=400) # Label
            window.e6 = Entry(window, width=25) # Entry window
            window.e6.place(x=5, y=425) # Placement of entry box
        elif window.cl == 0:
            label12 = Label(window, text="Oooohhh what a cool animal! My favorite is the red panda,\n such a unique and cute species!", font="times 12").place(x=5, y=400) # Label
            label13 = Label(window, text="What is your favorite season?", font="times 12").place(x=5, y=450) # Label
            window.e7 = Entry(window, width=25) # Entry window
            window.e7.place(x=5, y=475) # Placement of entry box
    elif displayState == 5:
        if window.cl == 1:
            label12 = Label(window,
                            text="Oooohhh what a cool animal! My favorite is the red panda,\n such a unique and cute species!",
                            font="times 12", justify=LEFT).place(x=5, y=450) # Label
            label13 = Label(window, text="What is your favorite season?", font="times 12").place(x=5, y=500) # Label
            window.e7 = Entry(window, width=25) # Entry window
            window.e7.place(x=5, y=525)  # Placement of entry box
        elif window.cl == 0:
            season = window.e7.get()
            if season == 'Fall':
                label13 = Label(window, text="Wow! That is my favorite season also! The colors of the leaves are amazing", font="times 12").place(x=5, y=500) # Label
                label14 = Label(window, text="Do you have any siblings in your family?", font="times 12").place(x=5, y=525) # Label
                window.e8 = Entry(window, width=25) # Entry window
                window.e8.place(x=5, y=550) # Placement of entry box
            else:
                label13 = Label(window,
                                text="Nice! My favorite season is Fall!",
                                font="times 12").place(x=5, y=500) # Label
                label14 = Label(window, text="Do you have any siblings in your family?", font="times 12").place(x=5,
                                                                                                                y=525) # Label
                window.e8 = Entry(window, width=25) # Entry window
                window.e8.place(x=5, y=550) # Placement of entry box
    elif displayState == 6:
        if window.cl == 1:
            season = window.e7.get()
            if season == 'Fall':
                label13 = Label(window, text="Wow! That is my favorite season also! The colors of the leaves are amazing", font="times 12").place(x=5, y=550) # Label
                label14 = Label(window, text="Do you have any siblings in your family?", font="times 12").place(x=5, y=575) # Label
                window.e8 = Entry(window, width=25) # Entry window
                window.e8.place(x=5, y=600) # Placement of entry box
            else:
                label13 = Label(window,
                                text="Nice! My favorite season is Fall!",
                                font="times 12").place(x=5, y=550) # Label
                label14 = Label(window, text="Do you have any siblings in your family?", font="times 12").place(x=5,
                                                                                                                y=575) # Label
                window.e8 = Entry(window, width=25) # Entry window
                window.e8.place(x=5, y=600) # Placement of entry box
        if window.cl == 0:
            siblings = window.e8.get()
            if siblings == 'Yes' or siblings == 'yes':
                label14 = Label(window, text="Very nice, back when I was born a human I grew up with a sister", font="times 12").place(x=5, y=575) # Label
                label15 = Label(window, text="What state were you born in?", font="times 12").place(x=5, y=600) # Label
                window.e9 = Entry(window, width=25) # Entry window
                window.e9.place(x=5, y=625) # Placement of entry box
            elif siblings == 'No' or siblings == 'no':
                label14 = Label(window, text="An only child I see", font="times 12").place(x=5,y=575) # Label
                label15 = Label(window, text="What state were you born in?", font="times 12").place(x=5, y=600) # Label
                window.e9 = Entry(window, width=25) # Entry window
                window.e9.place(x=5, y=625) # Placement of entry box
    elif displayState == 7:
        if window.cl == 1:
            siblings = window.e8.get()
            if siblings == 'Yes' or siblings == 'yes':
                label14 = Label(window, text="Very nice, back when I was born a human I grew up with a sister", font="times 12").place(x=5, y=625) # Label
                label15 = Label(window, text="What state were you born in?", font="times 12").place(x=5, y=650) # Label
                window.e9 = Entry(window, width=25) # Entry window
                window.e9.place(x=5, y=675) # Placement of entry box
            elif siblings == 'No' or siblings == 'no':
                label14 = Label(window, text="An only child I see", font="times 12").place(x=5,y=625) # Label
                label15 = Label(window, text="What state were you born in?", font="times 12").place(x=5, y=650) # Label
                window.e9 = Entry(window, width=25) # Entry window
                window.e9.place(x=5, y=675) # Placement of entry box
        if window.cl == 0:
            state = window.e9.get()
            if state == 'West Virginia':
                label16 = Label(window, text="My creator is also from there!", font="times 12").place(x=5, y=650) # Label
                label16 = Label(window, text="Well I thank you for your time but that is all the time we have,\n thank you for joining me today", font="times 12").place(x=5, y=675) # Label
            else:
                label16 = Label(window, text="What a lovely state", font="times 12").place(x=5, y=650) # Label
                label16 = Label(window, text="Well I thank you for your time but that is all the time we have,\n thank you for joining me today", font="times 12").place(x=5, y=675) # Label
    elif displayState == 8:
        if window.cl == 1:
            state = window.e9.get()
            if state == 'West Virginia':
                label16 = Label(window, text="My creator is also from there!", font="times 12").place(x=5, y=700) # Label
                label16 = Label(window, text="Well I thank you for your time but that is all the time we have,\n thank you for joining me today", font="times 12").place(x=5, y=725) # Label
            else:
                label16 = Label(window, text="What a lovely state", font="times 12").place(x=5, y=700) # Label
                label16 = Label(window, text="Well I thank you for your time but that is all the time we have,\n thank you for joining me today", font="times 12").place(x=5, y=725) # Label

    displayState += 1

label1 = Label(window, text ="Hi there! Welcome to the ChatBot station.\nI am going to ask you a series of questions and all you have to do is answer!", font="times 12", justify=LEFT).place(x=5, y =5) # Label
label2 = Label(window, text ="Lets get started", font="times 12").place(x=5, y =50) # Label
label3 = Label(window, text ="What is your first name?", font="times 12").place(x=5, y =75) # Label

e1 = Entry(window, width=25) # get values of e1
e1.place(x=5, y=100) # Placement of entry box

label4 = Label(window, text="What is your last name?", font="times 12").place(x=5, y=125) # Label
e2 = Entry(window, width=25) # get values of e2
e2.place(x=5, y=150) # Placement of entry box

b1 = Button(window, text='Enter', width=30, command=onClick).place(x=100, y=800) # Button

window.mainloop()

Output:


Related Solutions

Create a code where you click on the appropriate buttons on your Python GUI and it...
Create a code where you click on the appropriate buttons on your Python GUI and it turns on and off the corresponding LEDs for Arduino, please.
Python Create a tkinter GUI application that has two buttons on it. The first button should...
Python Create a tkinter GUI application that has two buttons on it. The first button should have in red text the word "Red" on it and the second button should have in blue text the word "Blue" on it. When the red button is clicked you should change the background color of the application window to red and when the blue button is pressed you should change the background color of the application window to blue. You should place your...
Topic is relates to Java programming! Code using java GUI 2. Create the following controls: a)...
Topic is relates to Java programming! Code using java GUI 2. Create the following controls: a) a TextField b) a Button c) a Text d) a Label 3. create the following container and put them the above controls: a) a VBox controller b) a BorderPane controller c) a GridPane
Using C# Windows App Form Create a simple calculator using +,-,*,/ Please show code GUI Code...
Using C# Windows App Form Create a simple calculator using +,-,*,/ Please show code GUI Code for calculator menus radio button input text boxes
modify the code below to create a GUI program that accepts a String from the user...
modify the code below to create a GUI program that accepts a String from the user in a TextField and reports whether or not there are repeated characters in it. Thus your program is a client of the class which you created in question 1 above. N.B. most of the modification needs to occur in the constructor and the actionPerformed() methods. So you should spend time working out exactly what these two methods are doing, so that you can make...
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA...
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA is >= 3.5, display 'Dean’s List' If the GPA is < 2.0, display 'Probation’ If the GPA is < 3.5 and >= 2.0, display 'Regular Standing' Run one test case for each case above and save the output.
Use pseudo code to plan a programming solution for the following: A GUI interface to ensure...
Use pseudo code to plan a programming solution for the following: A GUI interface to ensure a user is old enough to play a game. See additional resources above for additional resources. Properly formatted prompts to input name, address, phone number, and age. Instructions to ensure that the information is displayed back to the user. Also, the user must be 21. So, include instructions to display an appropriate message about whether or not the user can continue. Instructions that will...
This is using Python, it is utilizing code from a Fraction class to create a Binary...
This is using Python, it is utilizing code from a Fraction class to create a Binary Class Please leave comments so I may be able to learn from this. Instruction for Binary Class: Exercise 6.18: Design an immutable class BinaryNumber, in the style of our Fraction class. Internally, your only instance variable should be a text string that represents the binary value, of the form '1110100'. Implement a constructor that takes a string parameter that specifies the original binary value....
I did the complete programming in python , just want to use tkinter for GUI. please...
I did the complete programming in python , just want to use tkinter for GUI. please look at the 2nd part . i did some part of this program using tkinter but could not finis it. Thank you. import random image = 'w' # modified functions which accepts two numbers each and returns the respective # output def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def kidCalc():...
Using tkinter, create a GUI interface which accepts input of annual income. Using the table below,...
Using tkinter, create a GUI interface which accepts input of annual income. Using the table below, determine and output the income tax for that income. Tax Rate Income 10% $0 to $9,875.00;  12% $9,876.01 to $40,125.00; 22% $40,126 to $85,525.00; 24% $85,526.01 to $163,300.00. Test with the following income data: 163,300.00 9,876.01 85,525.00
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT