Home > Software engineering >  How to use Tkinter buttons for input something
How to use Tkinter buttons for input something

Time:12-22

I am making a rock paper scissor game, I just want to add 3 buttons "ROCK,PAPER,SCISSOR" But how do I make them to input something, like I pressed button "rock", rock has been input there here is my code

CodePudding user response:

Try this:

import tkinter as tk
    

def ROCK():
    print('Enter your Text:')
    Rock = input()
    print(Rock)
def PAPER():
    print('Enter your Text:')
    Paper = input()
    print(Paper)
def SCISSOR():
    print('Enter your Text:')
    Scissor = input()
    print(Scissor)

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

button = tk.Button(frame, 
                   text="ROCK", 
                   command=ROCK)
button.pack(side=tk.LEFT)
slogan = tk.Button(frame,
                   text="PAPER",
                   command=PAPER)
slogan.pack(side=tk.LEFT)
slogan = tk.Button(frame,
                   text="SCISSOR",
                   command=SCISSOR)
slogan.pack(side=tk.LEFT)

root.mainloop()

CodePudding user response:

Could you show the code please.

  • Related