Z
Z
Zero_002021-06-30 16:10:23
Python
Zero_00, 2021-06-30 16:10:23

Is there an alternative to get()?

It is necessary that get() does not accept a string, but a number.
For example:

x = Entry()
x.get() #принимает строку
x.???() #принимает число

If it doesn't exist, is there any way to replace it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ScriptKiddo, 2021-06-30
@Zero_00

from tkinter import *
from tkinter import messagebox as mb

root = Tk()
root.geometry('500x200')
root.resizable(False, False)
root.title('Деление на 3')
root['bg'] = 'grey22'
txt = Label(text='Напишите число:', fg='white', bg='black')
txt.grid()
ent = Entry()
ent.grid(column=2, row=0)


def divBy3():
    num = ent.get()
    if not num.isnumeric():
        mb.showerror(title='Ошибка', message='Произошла ошибка. Вы написали не число')
    else:
        num = int(num)
        oper = num / 3  # get принимает только строки :(
        if num % 3 == 0:
            mb.showinfo(title='Информация', message='Число делится на 3, результат: ' + str(oper))
        elif num % 3 != 0:
            mb.showinfo(title='Информация', message='Данное число не делится на 3!')



btn = Button(text='Нажать', width=15, command=divBy3)
btn.place(x=250)
root.mainloop()

U
Up0, 2021-07-02
@Up0

x = Entry()
a=x.get() #takes a string
b=int(x.get()) #takes an integer
c=float(x.get()) #takes a float number

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question