Z
Z
Zinder2020-06-24 21:14:15
Python
Zinder, 2020-06-24 21:14:15

How to open another widget on tkinter button click?

practical_work - directory
Part of code main widget main.py

import tkinter as tk
from tkinter import ttk
from  practical_work import workers


class Main(tk.Frame):
    def __init__(self, root):
        super().__init__(root)
        self.init_main()

    def init_main(self):
        toolbar = tk.Frame(bg='#d7d8e0', bd=2)
        toolbar.pack(side=tk.TOP, fill=tk.X)
        btn_workers = tk.Button(toolbar, text='test', bg='#d7d8e0', bd=0, image=self.add_img,
                                compound=tk.TOP, command=workers)
        btn_workers.pack(side=tk.RIGHT)

if __name__ == "__main__":
    root = tk.Tk()
    app = Main(root)
    app.pack()
    root.title("v_1")
    root.geometry("750x500+300+200")
    root.resizable(True, True)
    root.mainloop()

Part of the code imported widget workers.py
import tkinter as tk
from tkinter import ttk


class Workers(tk.Frame):
    def __init__(self, root):
        super().__init__(root)
        self.init_workers()

    def init_workers(self):
    self.tree.column('ID', width=30, anchor=tk.CENTER)
        self.tree.column('name', width=150, anchor=tk.CENTER)
        self.tree.column('salary', width=150, anchor=tk.CENTER)

        self.tree.heading('ID', text='ID')
        self.tree.heading('name', text='name')
        self.tree.heading('salary', text='salary')

        self.tree.pack()
        
root = tk.Tk()
    app = Workers(root)
    app.pack()
    root.title("Сотрудники")
    root.geometry("750x500+300+200")
    root.resizable(True, True)
    root.mainloop()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question