Python tkinter button disappear

hello sir,
in tkinter ,when write the " commond=send_message" in button ,button disappear from frame.
and also same with textarea.

    sms_btn=Button(new_left_frame,command=send_message,text="Send",width=11,font=("arial",10,"bold"),fg="red")
    sms_btn.place(x=230,y=110)

On the face of this, I’d say: check that the x and y coordinates are not outside of the boundaries of the new_left_frame object.

when “command=send_message” remove from code then button appear according to the coordinate provided by me.

Okay. In that case I’d be looking at what the function send_message() is doing.

Without a working example of the issue, all I can do is ‘best guess’ a solution.

I am calling new window from main window and in new window i declare main frame cover whole window and further its divide into two parts left and right.In left side I design name ,phone and message field and one send button which is used to send sms to student whatever written in message entry.
def smsWindow(self):
new_window = Toplevel()
new_window.title(“message Sending Window”)
new_window.geometry(“1200x700+200+100”)
#new_window.config(bg=“green”)
lbl_title=Label(new_window,text=“Every Solution Student Information System”,font=(‘times new roman’,30,‘bold’),fg=‘green’)
lbl_title.place(x=0,y=0,height=50,width=1250)
newMain_frame=Frame(new_window,bd=2,relief=RIDGE,bg=“green”)
newMain_frame.place(x=5,y=50,height=650,width=1350)
new_left_frame=LabelFrame(newMain_frame,bd=2,text=“Reminder Message to Student”,font=(“Times new roman”,15,‘bold’),relief=RIDGE,bg=“green”)
new_left_frame.place(x=6,y=0,height=610,width=500)

    #---------Display name of developer in bottom in new sms window--------------       
    developer_frame=Frame(newMain_frame,bd=2,relief=RIDGE,bg="green")
    developer_frame.place(x=5,y=610,height=30,width=1340)
    lbl_developer=Label(developer_frame,text="Developed by-Gaurav Kumar",font=("Ariel",12,"bold"),bg="green",fg="white")
    #lbl_developer.grid(row=0,column=0,sticky=W,padx=10)
    lbl_developer.place(x=900,y=0)
    lbl_copyright=Label(developer_frame,text="(c) All Rights Reserved 2023-2030",font=("Ariel",12,"bold"),bg="green",fg="white")
    lbl_copyright.grid(row=0,column=0,sticky=W,padx=10)

    lbl_name=Label(new_left_frame,text="Student's Name:",font=("Aril",12),bg="green",fg="white")
    lbl_name.grid(row=0,column=0,sticky=W,padx=10)
    txt_name=Entry(new_left_frame,textvariable=self.var_name,width=25,font=("arial",12,"bold"))
    txt_name.grid(row=0,column=1,padx=1,pady=5)

    lbl_phone=Label(new_left_frame,text="Phone No:",font=("Ariel",12),bg="green",fg="white")
    lbl_phone.grid(row=1,column=0,sticky=W,padx=10)
    txt_phone=Entry(new_left_frame,textvariable=self.var_phone,width=25,font=("arial",12,"bold"))
    txt_phone.grid(row=1,column=1,padx=1,pady=5)
     
    lbl_sms=Label(new_left_frame,text="Message:",font=("Ariel",12),bg="green",fg="white")
    lbl_sms.grid(row=2,column=0,sticky=W,padx=10)
    txt_sms=Entry(new_left_frame,textvariable=self.var_sms,width=25,font=("arial",12,"bold"))
    txt_sms.grid(row=2,column=1,padx=1,pady=5)

    sms_btn=Button(new_left_frame,command=send_message,text="Send",width=11,font=("arial",10,"bold"),fg="red")
    sms_btn.place(x=230,y=110)
    
    def send_message():
        message=txt_sms.get(1.0,END)
        number=txt_phone.get()
        auth='Ct3xieHkw1dL4GFUM50vJDh7sqAf2ujOYWQon8RpKb6PBXgEzVTRf9jyvCu1EZqlPOn0Qes5LkJp2DW3'
        url="https://www.fast2sms.com/dev/bulk"
        params={
            "authorization":auth,
            "message":message,
            "numbers":number,
            "sender_id":'FSTSMS',
            "route":'p',
            "language":'english'
        }
    
   
        response=pip._vendor.requests.get(url,params=params)
        dic=response.json()
        result=dic.get('return')
        if result==True:
            messagebox.showinfo("Sent message successfully","Message sent to Student:")
        else:
            messagebox.showerror("Error","Something went wrong") 

    new_window.mainloop()

The code formatting in your post is a little off (because you’ve not read/followed the directions) so I’ve had to guess at that for some part, but it’s not an over-complicated script, so I think I’ve got it right.

That said, I can’t reproduce the issue: sms_btn object ‘disappears’ – I click said button and it stays right where it was put.

To add: my only other observation is that you’re using two geometry managements: .grid() and .place(). I can’t see that as being the issue that you’re having, but its not exactly ‘Best Practice’ to mix those; either use .grid() or use .place()

1 Like

I suspect that at the point you create the button, it hasn’t seen the definition of send_message yet, so there’s a NameError exception which is being ‘swallowed’ by tkinter.

1 Like

It wouldn’t be reaching tkinter yet, as the NameError would happen right here in the Python code. But I think you’re very likely right; either the NameError is getting swallowed somewhere else, or there’s a completely different send_message that is actually getting called.

1 Like