Home > other >  I don't understand what the problem is with the code, it is very simple so this is an easy one
I don't understand what the problem is with the code, it is very simple so this is an easy one

Time:03-04

I don't understand what the problem is with the code, it is very simple so this is an easy one

This is my code:

import time
from tkinter import *

import pyautogui

root = Tk()
root.geometry('400x200')

def button_command():
    text = entry1.get()

    pyautogui.keyDown("w")
    time.sleep(text)
    pyautogui.keyUp("w")

    return None

entry1 = Entry(root, width= 20)
entry1.pack()

Button(root,text="Button", command=button_command).pack()

root.mainloop()

CodePudding user response:

sleep() takes in an integer, and you can easily convert string into int with int(string)

With your problem, you can change sleep(text) with sleep(int(text))

CodePudding user response:

In the python codes data type taken automatically. On line 13 you are asking datatype from user which is by default string sp you just need to typecast that in int.

instead of

 text = entry1.get()

you should use

 text = int(entry1.get())
  • Related