Hello! There are query strings:

enterme = Entry (root, width = 10) enterme2 = Entry (root, width = 10) 

and there is a function in the use of this variable:

 ramdme = random.randrange (int(enterme),int(enterme2)) 

An error occurs:

 TypeError: int() argument must be a string, a bytes-like object or a number, not 'Entry' 

How can I get the value obtained via Entry to int? All code:

 import tkinter as tk import tkinter.ttk as ttk import random root=tk.Tk() enterme = Entry (root, width = 10) enterme_2 = enterme.get() enterme2 = Entry (root, width = 10) enterme2_2 = enterme2.get() ramdme = random.randrange (int(enterme),int(enterme2)) enterme.place() enterme2.place() root.mainloop() 

    2 answers 2

    Naturally, you get an error; it is a bit strange to try to convert the input field to a number. You should first get the value of this field:

     val = enterme.get() int(val) 
    • I'll try it now ... - babyborn
    • ValueError: invalid literal for int () with base 10: '' - babyborn
    • Again, naturally, the empty string cannot be converted to a number. - Sergey Gornostaev
    • 2
      Show all the code. 99% sure that you have the code for receiving data from the field not in the event handler, but just further down the code. - Sergey Gornostaev
    • one
      @dimahimma, if some long-term action is performed that cannot be broken down into smaller ones, then you need to put it into a separate thread / process, and this is a separate big topic. - insolor

    You convert the input field to a number. I understand that you want to transfer data from the input field. Then you need to get them first. Here is the code:

     int(entrme.get())