Python Forum
[Tkinter] TKinter Remove Button Frame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] TKinter Remove Button Frame
#1
Hi All - How can I remove the button frame in my code? I have tried a few examples I found, but have had no luck. I see one argument example for 'borderwidth=0' but does not seem to change anything. I am using a toggle button with images. Attached picture is what I have showing for my button. The image has rounded corners, so I want to remove the frame of the button completely. Thanks for any help with this.

import tkinter as tk
from tkinter import *
from tkinter import messagebox
import requests
import http.client
import time
import json
   
path = ""

SONOFF_Temp  = 'http://192.168.0.130/cm?cmnd=status+10'
sonoff_url = 'NOT_INIT'


class RelayButton(tk.Button):
    """A button that toggles a relay"""
    def __init__(self, parent, url="", on_image=None, off_image=None, **kwargs):
        super().__init__(parent, image=off_image, command=self.toggle)
        self.url = url
        self._on = False
        self.on_image = on_image
        self.off_image = off_image
        self.label = Label(text="", bg="White", fg="Black", font=("Helvetica", 12))
        self.label.place(x=10,y=15)
        self.update_clock()
        self.templabel = Label(text="temp info", bg="White", fg="Black", font=("Helvetica", 12))
        self.templabel.place(x=10, y=40)
        #self.getTemp()
        self.master.configure(background="white")
        
    @property
    def on(self):
        """Return state of the relay"""
        return self._on
   
    @on.setter
    def on(self, on):
        """Set state of the relay"""
        
        self._on = on

        try:
            if on:
                requests.post(f"{self.url}cm?cmnd=Power On")
                self["image"] = self.on_image
            else:
                requests.post(f"{self.url}cm?cmnd=Power Off")
                self["image"] = self.off_image
        except:
            messagebox.showinfo("Error")
    def toggle(self):
        """Toggle state of the relay"""
        self.on = not self.on
        
    def update_clock(self):
        now = time.strftime("%I:%M:%S %p " + ' - ' + "%x")
        self.label.configure(text='Time/Date:  ' + now)
        self.after(1000, self.update_clock)
        
    def getTemp(self):
        sonoff_url = SONOFF_Temp
        sonR1 = requests.get(sonoff_url)
        x = json.loads(sonR1.text)
        status = x["StatusSNS"]
        timestamp = status["Time"]
        device_names = list(status.keys())[1:-1]
        temp_units = status["TempUnit"]
        
        for name in device_names:
            device = status[name]
            #print(f'ID={name}, Temperature={device["Temperature"]} {temp_units}')
            self.templabel.configure(text='Living Room '+f'Temperature: {device["Temperature"]} {temp_units}')
            self.after(5000, self.getTemp)
            
   
def new_button(name, url, parent, row, column, **kwargs):
    """Convenience functon that creates a RelayButton"""
    on_image = tk.PhotoImage(file=f"{path}{name}_on.png")
    off_image = tk.PhotoImage(file=f"{path}{name}_off.png")
    button = RelayButton(parent, url, on_image, off_image, **kwargs)
    button.grid(row=row, column=column, padx=70, pady=110)
    return button


   
def main():
    app = tk.Tk()
    app.title('Home Relay Control')
    buttons = [
        #new_button('lvgRoom', "http://192.168.0.101/", app, 0, 0),
        new_button('frPorch', "http://192.168.0.130/", app, 0, 1)
        ]
    
    for b in buttons:
        b.on = False
    app.mainloop()
    
    
if __name__ == "__main__":
    main()

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
TKinter Remove Button Frame - by Nu2Python - Jan-15-2024, 06:00 AM
RE: TKinter Remove Button Frame - by JamesGreenwald - Jan-15-2024, 01:46 PM
RE: TKinter Remove Button Frame - by deanhystad - Jan-15-2024, 09:28 PM
RE: TKinter Remove Button Frame - by Nu2Python - Jan-16-2024, 04:49 PM
RE: TKinter Remove Button Frame - by rob101 - Jan-15-2024, 09:28 PM
RE: TKinter Remove Button Frame - by menator01 - Jan-16-2024, 12:07 AM
RE: TKinter Remove Button Frame - by rob101 - Jan-16-2024, 04:54 PM
RE: TKinter Remove Button Frame - by Nu2Python - Jan-16-2024, 05:54 PM
RE: TKinter Remove Button Frame - by rob101 - Jan-16-2024, 06:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - touchscreen, push the button like click the mouse John64 5 957 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  [Tkinter] Help running a loop inside a tkinter frame Konstantin23 3 1,660 Aug-10-2023, 11:41 AM
Last Post: Konstantin23
  tkinter mapview in a frame janeik 2 1,390 Jun-22-2023, 02:53 PM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 5,202 May-25-2023, 07:37 PM
Last Post: deanhystad
  Can't get tkinter button to change color based on changes in data dford 4 3,494 Feb-13-2022, 01:57 PM
Last Post: dford
  Creating a function interrupt button tkinter AnotherSam 2 5,630 Oct-07-2021, 02:56 PM
Last Post: AnotherSam
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 5,106 Oct-01-2021, 05:00 PM
Last Post: Yoriz
  [Tkinter] Trouble changing Font within tkinter frame title AnotherSam 1 4,212 Sep-30-2021, 05:57 PM
Last Post: menator01
  tkinter showing image in button rwahdan 3 5,720 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  tkinter frame camera opencv Nick_tkinter 9 5,559 Mar-21-2021, 06:41 PM
Last Post: Nick_tkinter

Forum Jump:

User Panel Messages

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