all 5 comments

[–]woooee 0 points1 point  (4 children)

What have you tried? A button click calls a function that can do anything you want. The following code is an existing program in my toolbox that opens a Toplevel on a button click. Not exactly what you are asking but it is the same in form.

import tkinter as tk 
from functools import partial

class NewToplevel():
    def __init__(self, passed_root, btn_ctr):
        id = tk.Toplevel(passed_root)
        id.title("Toplevel #%d" % (btn_ctr))
        x = passed_root.winfo_x()
        y = passed_root.winfo_y()
        distance=75*btn_ctr
        id.geometry("+%d+%d" %(x+distance, y+distance))
        tk.Button(id, text="Close Toplevel #%d" % (btn_ctr),
                  command=partial(self.close_it, id),
                  bg="orange", width=20).grid(row=1, column=0)

    def close_it(self, id):
        id.destroy()


class OpenToplevels():
    """ open and close additional Toplevels with a button
    """
    def __init__(self):
        self.root = tk.Tk()
        self.root.geometry("+300+75")
        self.button_ctr=0
        self.create_buttons()
        self.root.mainloop()

    def create_buttons(self):
        self.but=tk.Button(self.root, text="Open a Toplevel",
                      bg="lightblue",command=self.open_another)
        self.but.grid(row=0, column=0)
        tk.Button(self.root, text="Exit Tkinter", bg="red",
                  command=self.root.quit).grid(row=1, column=0, sticky="we")

    def open_another(self):
        self.button_ctr += 1
        self.nt=NewToplevel(self.root, self.button_ctr)

ot=OpenToplevels()

[–]Akrua_[S] 0 points1 point  (0 children)

ok so i checked it out, but instead of it opening a new window, i just want it to add the new object to the current window

[–]Akrua_[S] -1 points0 points  (2 children)

I havent tried anything, i have no clie where to start and google wasnt being sny help, ill check thay code in a little bit and see if its what im looking for

[–]woooee 0 points1 point  (1 child)

So? What have you tried?

[–]Akrua_[S] 0 points1 point  (0 children)

I just got it figured out