From 7c225dc62d0f40875c57287842ff5e41456f8568 Mon Sep 17 00:00:00 2001 From: Taiko2k Date: Thu, 27 Jan 2022 00:57:32 +1300 Subject: [PATCH] Update README.md --- README.md | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 08dd033..5c60e57 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,11 @@ Prerequisite: You have learnt the basics of Python. Ideally have some idea of ho Topics covered: - A basic GTK window - - Adding basic button widget - - Introducing the box layout - - Add check button, a switch and a slider - - Add a custom header bar + - Widgets: Button, check button, switch, slider + - Layout: Box layout + - Adding a custom header bar - Showing an open file dialog - - Add a button with a menu + - Adding a menu button with a menu - Custom drawing with Cairo - Handling mouse input - Setting the cursor @@ -189,10 +188,41 @@ def hello(self, button): self.close() ``` + ![Our window so far](twoitems.png) When we click the button, we can check the state of the checkbox! +### Extra Tip: Radio Buttons + +Check buttons can be turned into radio buttons by adding them to a group. You can do it using the `.set_group` method like this: + +```python +radio1 = Gtk.CheckButton(label="test") +radio2 = Gtk.CheckButton(label="test") +radio3 = Gtk.CheckButton(label="test") +radio2.set_group(radio1) +radio3.set_group(radio1) +``` + +You can handle the toggle signal like this: + +```python +radio1 = Gtk.CheckButton(label="test") +radio1.connect("toggled", self.radio_toggled) +``` + +When connecting a signal its helpful to pass additional paramiters like as follows. This way you can have one functon handle events from multiple widgets. Just forget to handle the extra paramiter in your handler function. + + +```python +radio1 = Gtk.CheckButton(label="test") +radio1.connect("toggled", self.radio_toggled, "test") +``` + +(This can apply to other widgets too) + + ## Add a switch For our switch, we'll want to put our switch in a ***Box***, otherwise it'll look all stretched.