Good evening,
I would like to build a tkinter interface with several buttons leading to differents script. Those script are functions in another folder.
In the example I built to explain my problem, the main script is test.py in the working folder and it calls the Test.py file in the BFoctions subfolder.
the test.py:
from BFonctions.Test import Affich
import tkinter as tk
from tkinter import *
from tkinter import ttk, messagebox
MaiN= tk.Tk()
MaiN.geometry('200x100')
btn = Button(MaiN, text="Créer une nouvelle fenêtre", command = Affich)
btn.pack(pady = 10)
MaiN.mainloop()
just create a button that calls the Affich function in the BFonctions/Test.py
the function:
import tkinter as tk
from tkinter import *
from tkinter import ttk, messagebox
def Affich():
root = tk.Tk()
root.title("Liste chèvres")
root.geometry("950x900")
text_var = tk.StringVar()
text_var.set("test")
label = tk.Label(root,textvariable=text_var,font=("Arial", 16, "bold"),fg="black",wraplength=500,height=3, bg='lightblue' )
label.grid(row = 0, column = 0, sticky = W)
Filterbutton1 = IntVar()
FilterButton1 = Checkbutton(root, text = "test",variable =
Filterbutton1,onvalue = 1,offvalue = 0,height = 2, width = 10)
FilterButton1.grid(row = 1, column = 0, sticky = W)
root.mainloop
create a label and a checkbox.
the checkbox is fonctionning correctly, however the label is not display
I obtained a similar result with a tk.Toplevel widget exept there is an additional and unnecessary window displayed.
Is there some change in my code that would allow to obtain the desired behavior?
thank you per advance
Affichcode. Also you should usetk.Toplevel()to create a new window rather than creating a newtk.Tk()instance. As-written, this is essentially creating two totally separate tkinter applications.