Python Forum
[Tkinter] AttributeError: 'App' object has no attribute 'set_text'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] AttributeError: 'App' object has no attribute 'set_text'
#1
I am creating a python tkinter gui application.When i run my code the gui works fine but the buttons are not working properly.Please see the code below:
from tkinter import *
class App:
	def __init__(self,master):
		#Variables
		account_number = IntVar().set("")
		pin_number = StringVar()
		
		#Frames
		Main = Frame(master)
		Main.pack()
		Top = Frame(root, bd=2,  relief=RIDGE,borderwidth=0,highlightthickness=0)
		Top.pack(side=TOP, fill=X,pady=36)
		Form = Frame(root,height=200)
		Form.pack(side=TOP)
		 
		#Labels
		self.lbl_title = Label(Top,text = "FedUni Banking",font=("Arial",32))
		self.lbl_title.pack()
		self.lbl_account = Label(Form,text = "Account Number / PIN",font=("Arial",11))
		self.lbl_account.grid(row=0,sticky=E)
		
		#Textboxes
		self.tb_account = Entry(Form,width=13,textvariable=account_number,font=("Arial",15))
		self.tb_account.grid(row=0,column=1,ipady=18)
		self.tb_pin = Entry(Form,width=13,show="*",textvariable=pin_number,font=("Arial",15))
		self.tb_pin.grid(row = 0,column = 2,ipady=18)
		
		#Buttons
		self.btn_1 = Button(Form,text="1",width=20,height=7,command = lambda:self.set_text("1"))
		self.btn_1.grid(row=1,column=0)
		self.btn_2 = Button(Form,text="2",width=20,height=7,command = lambda:self.set_text("2"))
		self.btn_2.grid(row=1,column=1)
		self.btn_3 = Button(Form,text="3",width=20,height=7,command = lambda:self.set_text("3"))
		self.btn_3.grid(row=1,column=2)
		self.btn_4 = Button(Form,text="4",width=20,height=7,command = lambda:self.set_text("4"))
		self.btn_4.grid(row=2,column=0)
		self.btn_5 = Button(Form,text="5",width=20,height=7,command = lambda:self.set_text("5"))
		self.btn_5.grid(row=2,column=1)
		self.btn_6 = Button(Form,text="6",width=20,height=7,command = lambda:self.set_text("6"))
		self.btn_6.grid(row=2,column=2)
		self.btn_7 = Button(Form,text="7",width=20,height=7,command = lambda:self.set_text("7"))
		self.btn_7.grid(row=3,column=0)
		self.btn_8 = Button(Form,text="8",width=20,height=7,command = lambda:self.set_text("8"))
		self.btn_8.grid(row=3,column=1)
		self.btn_9 = Button(Form,text="9",width=20,height=7,command = lambda:self.set_text("9"))
		self.btn_9.grid(row=3,column=2)
		self.btn_cancel = Button(Form,text="Cancel/Clear",bg="red",width=20,height=7,command = lambda:clear())
		self.btn_cancel.grid(row=4,column=0)
		self.btn_0 = Button(Form,text="0",width=20,height=7,command = lambda:self.set_text("0"))
		self.btn_0.grid(row=4,column=1)
		self.btn_login = Button(Form,text="Login",bg="green",width=20,height=7,command = lambda:login())
		self.btn_login.grid(row=4,column=2)
		
		#Functions
		

		def set_text(e,text):
			widget = e.focus_get()
			if widget in e.entries:
			    widget.insert(0, text)
	    
		def clear():
			self.tb_pin.delete(0,END)

		
root = Tk()
root.title("FedUni Banking")
root.geometry("440x640")
app = App(root)
root.mainloop()
Reply


Messages In This Thread
AttributeError: 'App' object has no attribute 'set_text' - by Sahil1313 - Jun-15-2018, 08:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  'NoneType' object has no attribute 'get' zunebuggy 8 1,417 Oct-13-2023, 06:39 PM
Last Post: zunebuggy
  tkinter AttributeError: 'GUI' object has no attribute pfdjhfuys 3 1,601 May-18-2023, 03:30 PM
Last Post: pfdjhfuys
  [Kivy] Windows 10: AttributeError: 'WM_PenProvider' object has no attribute 'hwnd' mikepy 1 2,351 Feb-20-2023, 09:26 PM
Last Post: deanhystad
  [Tkinter] Can't update label in new tk window, object has no attribute tompranks 3 3,575 Aug-30-2022, 08:44 AM
Last Post: tompranks
  AttributeError: 'NoneType' object has no attribute 'get' George87 5 15,539 Dec-23-2021, 04:47 AM
Last Post: George87
  [PyQt] AttributeError: 'NoneType' object has no attribute 'text' speedev 9 11,486 Sep-25-2021, 06:14 PM
Last Post: Axel_Erfurt
  [Tkinter] AttributeError: '' object has no attribute 'tk' Maryan 2 14,721 Oct-29-2020, 11:57 PM
Last Post: Maryan
  [Tkinter] AttributeError: 'tuple' object has no attribute 'replace' linuxhacker 7 6,911 Aug-08-2020, 12:47 AM
Last Post: linuxhacker
  [Kivy] AttributeError: 'NoneType' object has no attribute 'bind' faszination_92 2 6,291 Apr-12-2020, 07:01 PM
Last Post: Larz60+
  AttributeError: '_tkinter.tkapp' object has no attribute 'place_forget' edphilpot 5 9,224 Dec-20-2019, 09:52 PM
Last Post: joe_momma

Forum Jump:

User Panel Messages

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