Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

tkinter add new element into grid by click

import tkinter as tk


class App(tk.Frame):

    def __init__(self, master, *args, **kwargs):
        tk.Frame.__init__(self, master, *args, **kwargs)
        self.master = master
        self.label_frame = tk.Frame(self.master)
        self.label_frame.grid()

        self.label_list = []

        for i in range(2):
            self.label_list.append(tk.Label(self.label_frame, text="Some Data"))
            self.label_list[i].grid(row=i)

        self.label_list.append(tk.Button(self.label_frame, text="Add new data", command=self.add_new_data))
        self.label_list[2].grid(row=2)

    def add_new_data(self):
        self.label_list.insert(1, tk.Label(self.label_frame, text="<<New Data>>"))

        for widget in self.label_frame.children.values():
            widget.grid_forget() 

        for ndex, i in enumerate(self.label_list):
            i.grid(row=ndex)


if __name__ == "__main__":
    root = tk.Tk() 
    my_app = App(root)
    root.mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: how to save an object in python to disk 
Python :: difference in django project view and app view 
Python :: morphological filter example python 
Python :: how to open a different version of python on my macc 
Python :: flask-restx custom ui 
Python :: openpyxl add_filter column 
Python :: zeromq pub sub example python 
Python :: what are the mouseX/mouseY variebles in pycharm 
Python :: Group the values for each key in the RDD into a single sequence. 
Python :: update profile rasterio pyton 
Python :: pydrive list shared folder 
Python :: PyQT5 reset color 
Python :: data wrangling python 
Python :: timedelta64 total_mins 
Python :: hovering over canvas item tkinter event 
Python :: convert fisheye video to normal python 
Python :: set title name in steamlit 0.790 
Python :: pyttsx python not working 
Python :: !python read data from mysql and export to xecel 
Python :: raspberry pi led python 
Python :: what does 0 for in array mean python 
Python :: replace special from beginning of string 
Python :: login urls 
Python :: pylatex add package 
Python :: numpy rolling 2d 
Python :: c++ to python code converter 
Python :: python split clever looping 
Python :: python chunks 
Python :: convert_hex_to_ASCII_3.py 
Python :: convert multidimentional numpy array to string and back 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =