Diferències

Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.

Enllaç a la visualització de la comparació

info:cursos:pue:python-pcpp1:m3:2.1 [28/12/2023 20:07] – creat mateinfo:cursos:pue:python-pcpp1:m3:2.1 [28/12/2023 20:09] (actual) mate
Línia 138: Línia 138:
 {{:info:cursos:pue:python-pcpp1:m3:pasted:20231228-110745.png}} {{:info:cursos:pue:python-pcpp1:m3:pasted:20231228-110745.png}}
  
 +<code python>
 +import tkinter as tk
 +from tkinter import messagebox
 +
 +
 +def show():
 +    messagebox.showinfo("", "radio_1=" + str(radio_1_var.get()) +
 +                        ",radio_2=" + str(radio_2_var.get()))
 +
 +
 +def command_1():
 +    radio_2_var.set(radio_1_var.get())
 +
 +
 +def command_2():
 +    radio_1_var.set(radio_2_var.get())
 +
 +
 +window = tk.Tk()
 +button = tk.Button(window, text="Show", command=show)
 +button.pack()
 +radio_1_var = tk.IntVar()
 +radio_1_1 = tk.Radiobutton(window, text="pizza", variable=radio_1_var, value=1, command=command_1)
 +radio_1_1.select()
 +radio_1_1.pack()
 +radio_1_2 = tk.Radiobutton(window, text="clams", variable=radio_1_var, value=2, command=command_1)
 +radio_1_2.pack()
 +radio_2_var = tk.IntVar()
 +radio_2_1 = tk.Radiobutton(window, text="FR", variable=radio_2_var, value=2, command=command_2)
 +radio_2_1.pack()
 +radio_2_2 = tk.Radiobutton(window, text="IT", variable=radio_2_var, value=1, command=command_2)
 +radio_2_2.select()
 +radio_2_2.pack()
 +window.mainloop()
 +
 +</code>
 +
 +The program defines two separate Radiobutton groups, consisting of two Radiobuttons. These groups are coupled, as their callbacks change the opposite group to reflect the state of their own group. Thanks to that, you can choose a meal and change country, or you can change country and the meal will select itself automatically.
 +
 +Let’s say “Goodbye” now – we’ll meet again soon to discuss some non-clickable widgets!
  • info/cursos/pue/python-pcpp1/m3/2.1.1703790472.txt.gz
  • Darrera modificació: 06/07/2026 18:29
  • (edició externa)