Python Forum
[Tkinter] Inserting numbers into entry box in a widget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Inserting numbers into entry box in a widget
#2
You cant call insert on a StringVar it does not have this method.
Entry widgets have an insert method maybe that what you are trying to do, you will need to keep a reference to the entry widget in the class to access it.
Also note that insert parameters of a Entry are an index and a string you have used an index and a int.

https://effbot.org/tkinterbook/entry.htm...ert-method Wrote:insert(index, string)
Inserts text at the given index. Use insert(INSERT, text) to insert text at the cursor, insert(END, text) to append text to the widget.
  • index
    Where to insert the text.
  • string
    The text to insert.

All the code you posted is overwhelming and not necessary to show the problem you are having, strip out the the unnecessary parts like below.
# imports

from tkinter import *

from tkinter import messagebox as ms


# main Class

class main:

    def __init__(self, master):
        # Window
        self.master = master
        # Some Usefull variables
        self.level1 = StringVar()  # lets
        self.monitor()

    def monitor(self):

        self.disp1 = Frame(self.master, padx=10, pady=10)

        Label(self.disp1, text='Level 1: ', font=(
            '', 20), pady=5, padx=5).grid(sticky=W)
        Entry(self.disp1, textvariable=self.level1,
              bd=5, font=('', 15)).grid(row=0, column=1)
        Button(self.disp1, text=' Display Counts ', bd=3, bg="green", font=(
            '', 15), padx=5, pady=5, command=self.level).grid()  # comand delet inm sqlite3
        self.disp1.pack()

    def level(self):

        lv = int(4)
        self.level1.insert(0, 4)
        print("Hello World")


root = Tk()

root.title("Bearing Current Program")

main(root)

root.mainloop()
When you get an error post the error traceback
Error:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\Dave\Anaconda3\lib\tkinter\__init__.py", line 1705, in __call__ return self.func(*args) File "c:/Users/Dave/Documents/VS Code WorkSpaces/Python Forum/general/forumpost.py", line 34, in level self.level1.insert(0, 4) AttributeError: 'StringVar' object has no attribute 'insert'
It is advisable not to use star imports
https://python-forum.io/Thread-Namespace...th-imports
Reply


Messages In This Thread
RE: Inserting numbers into entry box in a widget - by Yoriz - Aug-11-2019, 11:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: could not convert string to float: '' fron Entry Widget russellm44 5 722 Mar-06-2024, 08:42 PM
Last Post: russellm44
  [Tkinter] entry widget DPaul 5 1,543 Jul-28-2023, 02:31 PM
Last Post: deanhystad
  Tkinter Exit Code based on Entry Widget Nu2Python 6 3,021 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  Line numbers in Text widget rfresh737 3 5,451 Apr-15-2021, 12:30 PM
Last Post: rfresh737
  method to add entries in multi columns entry frames in self widget sudeshna24 2 2,270 Feb-19-2021, 05:24 PM
Last Post: BashBedlam
  Entry Widget issue PA3040 16 6,887 Jan-20-2021, 02:21 PM
Last Post: pitterbrayn
  [Tkinter] password with Entry widget TAREKYANGUI 9 6,015 Sep-24-2020, 05:27 PM
Last Post: TAREKYANGUI
  [Tkinter] Get the last entry in my text widget Pedroski55 3 6,433 Jul-13-2020, 10:34 PM
Last Post: Pedroski55
  How to retreive the grid location of an Entry widget kenwatts275 7 4,644 Apr-24-2020, 11:39 PM
Last Post: Larz60+
  POPUP on widget Entry taratata2020 4 3,777 Mar-10-2020, 05:04 PM
Last Post: taratata2020

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020