0

My problem is, that then i open a second window with a button in the first window, the spinbox in the second window does not give an output. If i start the second one individually, it works as expectet. I used the pygub designer to design the windows.

Here is my Code from the first (main) window:

import tkinter.ttk as ttk
from tkinter import messagebox

import Test2


class NewprojectApp:
   def __init__(self, master=None):
       # build ui
       toplevel1 = tk.Tk() if master is None else tk.Toplevel(master)
       toplevel1.configure(height=500, width=500)
       entry1 = ttk.Entry(toplevel1)
       self.Entrytest1 = tk.StringVar()
       entry1.configure(textvariable=self.Entrytest1)
       entry1.pack(padx=10, pady=10, side="top")
       spinbox1 = ttk.Spinbox(toplevel1)
       self.Spinbox1 = tk.IntVar()
       spinbox1.configure(from_=0, increment=1, textvariable=self.Spinbox1, to=10)
       spinbox1.pack(padx=10, pady=10, side="top")
       button2 = ttk.Button(toplevel1)
       button2.configure(text="Neuesfenster")
       button2.pack(padx=10, pady=10, side="top")
       button2.bind("<ButtonPress>", self.ereignisbehandler, add="")

       # Main widget
       self.mainwindow = toplevel1

   def run(self):
       self.mainwindow.mainloop()

   def ereignisbehandler(self, event=None):
       messagebox.showinfo("Test", self.Spinbox1.get())
       Test2.secondwindow()


if __name__ == "__main__":
   app = NewprojectApp()
   app.run()

And the second window:

import tkinter as tk
import tkinter.ttk as ttk
from tkinter import messagebox


class NewprojectApp2:
    def __init__(self, master=None):
        # build ui
        toplevel2 = tk.Tk() if master is None else tk.Toplevel(master)
        toplevel2.configure(height=500, width=500)
        entry2 = ttk.Entry(toplevel2)
        self.Entrytest1 = tk.StringVar()
        entry2.configure(textvariable=self.Entrytest1)
        entry2.pack(padx=10, pady=10, side="top")
        spinbox2 = ttk.Spinbox(toplevel2)
        self.Spinbox2 = tk.IntVar()
        spinbox2.configure(from_=0, increment=1, state="normal", textvariable=self.Spinbox2, to=10)
        spinbox2.pack(padx=10, pady=10, side="top")
        button4 = ttk.Button(toplevel2)
        button4.configure(text="Neuesfenster")
        button4.pack(padx=10, pady=10, side="top")
        button4.bind("<ButtonPress>", self.ereignisbehandler, add="")

        # Main widget
        self.mainwindow = toplevel2

    def run(self):
        self.mainwindow.mainloop()

    def ereignisbehandler(self, event=None):
        messagebox.showinfo("Test", self.Spinbox2.get())


if __name__ == "__main__":
    app = NewprojectApp2()
    app.run()

def secondwindow():
    app = NewprojectApp2()
    app.run()

Thank you for helping!

hepiep
  • 9
  • 4
  • 1
    You're calling `Tk()` more than once, which leads to non-working Vars (among various other problems). You have code that will use `Toplevel()` to create secondary windows, which is the solution to this problem - but this is never being used, because you're not passing that `master` parameter to your classes. – jasonharper Oct 13 '22 at 15:11

0 Answers0