vérification Etat Checkbutton
Bonjour,
je test le widget Checkbutton sur un TopLevel.
je me suis inspiré de ceci dans une frame principal
https://www.delftstack.com/fr/tutori...r-checkbutton/
mon test sur une Toplevel intialise le widget Checkbutton avec le carré rempli entièrement en bleu alors qu'il devrait être vide.
le but est de capter l'état du widget selon le choix de l'utilisateur.
voici le code "setup.py" :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
# coding:utf-8
#version 3.x python
# ==================================================
# ID python
# ==================================================
from tkinter import *
import tkinter as tk
from tkinter import ttk
import Maintenances
# ==================================================
# Fenêtre Principal - Configuration
# ==================================================
root = tk.Tk() # Crée une instance Tk class
root.title("Principal")
root.resizable(False, False) # Fenêtre verrouillée
window_height = 150
window_width = 150
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_cordinate = int((screen_width/2) - (window_width/2))
y_cordinate = int((screen_height/2) - (window_height/2))
root.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))
def New_Maintenances():
Maintenances.Maintenances_Contenu()
# ==================================================
# Frames
# ==================================================
# --- Frame vertival droite ---
LeftFrame = tk.LabelFrame(root, text="[+++]", font=('verdana', 8, ''), foreground="blue", relief=SOLID, borderwidth=0)
LeftFrame.place(x=5, y=5, width=123, height=200)
# Buttons
Bt4 = tk.Button(LeftFrame, width=16, text="checkbutton", font=('verdana', 8, ''), command=New_Maintenances)
Bt4.grid(row=4, column=0)
root.mainloop() |
voici le code "Maintenance.py" :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
# coding:utf-8
# version 3.x python
from tkinter import *
import tkinter as tk
from tkinter.ttk import *
from tkinter.ttk import Button
from tkinter import Toplevel
def Maintenances_Contenu():
Maintenance_Frame = tk.Toplevel()
Maintenance_Frame.title('Toplevel')
Maintenance_Frame.geometry("200x200+30+30") # ("X Y+ 30+30") 561x305
Maintenance_Frame.resizable(width=False, height=False) # Fenêtre verrouillée
Maintenance_Frame.attributes("-toolwindow", 1) # Supprime les boutons Réduire/Agrandir
Maintenance_Frame.attributes("-topmost", 1) # au priemier plan
# ==============================================================
# Cadres
# ==============================================================
FrameForm = Frame(Maintenance_Frame, width=910) #, relief=SOLID, borderwidth=1)
FrameForm.grid(row=1, column=0)
FrameRight = LabelFrame(FrameForm, text="[----]", width=550, height=304, relief=SOLID, borderwidth=1)
FrameRight.grid(row=0, column=1, sticky=W)
chkValue = tk.BooleanVar()
chkValue.set(False)
print("The checkbutton original value is {}".format(chkValue.get()))
print("Etat d'origine --> Désactivé :", chkValue.get())
print("\n")
chkExample = Checkbutton(FrameRight, text='texte', var=chkValue)
chkExample.place(x=2, y=102) |
merci