Python Forum
[Tkinter] Hide clicked buttons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Hide clicked buttons
#6
Hi Yoriz

Awesome. Thanks a lot for your excellent response and also for the good input about the from tkinter import *. Your code works absolutely perfect and fulfils my needs.

Best Wishes,
Rubberduck

(Jun-01-2021, 06:29 PM)Yoriz Wrote: Don't use from tkinter import * see Namespace flooding with * imports
If you don't want the widget anymore you can destroy it.
import tkinter as tk
import csv


def yield_csv(file_path):
    with open(file_path, 'r') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        for line in csv_reader:
            yield line


class App(tk.Tk):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.title('Fahrzeugkontrolle')
        self.geometry('500x1000')
        self.string_var = tk.StringVar()
        self.string_var.set("prove")
        self.r_btns = {}

        csv_ = yield_csv('PostDummy.csv')
        next(csv_)
        for line in csv_:
            value = f'{line[3]}, {line[1]}'
            r_btn = tk.Radiobutton(self, text=line[3],
                                   variable=self.string_var, value=value)
            r_btn.pack(anchor=tk.W)
            self.r_btns[value] = r_btn

        myLabel = tk.Label(self, text=self.string_var.get())
        myLabel.pack()

        myButton = tk.Button(self, text="OK", command=self.on_btn)
        myButton.pack()

    def on_btn(self):
        value = self.string_var.get()
        myLabel = tk.Label(self, text=value)
        myLabel.pack()
        self.r_btns[value].destroy()


if __name__ == '__main__':
    app = App()
    app.mainloop()
Reply


Messages In This Thread
Hide clicked buttons - by Rubberduck - Jun-01-2021, 01:43 PM
RE: Hide clicked buttons - by deanhystad - Jun-01-2021, 02:58 PM
RE: Hide clicked buttons - by Rubberduck - Jun-01-2021, 04:35 PM
RE: Hide clicked buttons - by Yoriz - Jun-01-2021, 06:29 PM
RE: Hide clicked buttons - by Rubberduck - Jun-02-2021, 12:37 PM
RE: Hide clicked buttons - by deanhystad - Jun-01-2021, 07:13 PM
RE: Hide clicked buttons - by Rubberduck - Jun-02-2021, 12:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Button to +1 in text box everytime it's clicked martyloo 2 213 May-02-2024, 10:30 AM
Last Post: lillydalson
  [PyQt] Button clicked not working catlessness 10 8,351 Oct-21-2021, 12:36 PM
Last Post: catlessness
  [tkinter] not getting checkbutton value when clicked OogieM 5 6,213 Sep-20-2020, 04:49 PM
Last Post: deanhystad
  [PyQt] Avoid clicked event from button when button is not physically selected and clicked mart79 2 2,382 May-05-2020, 12:54 PM
Last Post: mart79
  [Tkinter] Displaying Data from a database and run a function when clicked? PythonNPC 1 2,093 Mar-11-2020, 08:16 PM
Last Post: Larz60+
  tkinter button not accessing the command when clicked jhf2 1 3,633 Nov-23-2019, 10:17 PM
Last Post: DT2000
  [Tkinter] How to check after 30 minutes if Buttons have been clicked? bmghafoor 1 2,126 Aug-09-2019, 04:57 PM
Last Post: Yoriz
  [PyQt] Hide Dock Icon for QSystemTrayIcon App AeglosGreeenleaf 0 3,338 Jun-20-2019, 07:21 PM
Last Post: AeglosGreeenleaf
  General help with hide show status bar for a begineer in python ArakelTheDragon 0 2,806 Mar-17-2019, 11:58 AM
Last Post: ArakelTheDragon
  Hide button when clicked frequency 2 8,859 Dec-24-2018, 02:10 PM
Last Post: frequency

Forum Jump:

User Panel Messages

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