can someone pointing me how to get a command in checkbutton1
be executed after user check it and hit ok button?.for
example:
in the attached picture, if user check the 'open terminal button'
and hit execute,the program open terminal window.
Ene Uran 638 Posting Virtuoso
You got to give us your code.
strobon 0 Newbie Poster
hello.py :
#!/usr/bin/env python
import sys
import os
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
class action:
def __init__(self):
#set the glade
self.gladefile=("action.glade")
self.wTree=gtk.glade.XML(self.gladefile)
#create dictionary and connect it
dic = { "on_button1_clicked" : self.button1_clicked,
"on_button2_clicked" : gtk.main_quit,
"on_checkbutton1_toggled" : self.checkbutton1_toggled}
self.wTree.signal_autoconnect(dic)
def button1_clicked(self,widget):
checked = self.checkbutton1_toggled.get_active()
if checked:
os.popen("gnome-terminal")
else:
pass
#here i got confused how to set the checkbutton signal
def checkbutton1_toggled(self,widget):
if widget.get_active():
os.popen("gnome-terminal")
else:
pass
if __name__ == "__main__":
wine = action()
gtk.main()
action.glade :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.2 on Sun Feb 15 23:22:30 2009 -->
<glade-interface>
<widget class="GtkWindow" id="window1">
<property name="visible">True</property>
<property name="title" translatable="yes">Hello World</property>
<signal name="destroy" handler="on_window1_destroy"/>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<child>
<widget class="GtkButton" id="button1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">gtk-execute</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button1_clicked"/>
</widget>
</child>
<child>
<widget class="GtkCheckButton" id="checkbutton1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK</property>
<property name="tooltip" translatable="yes">Partition Editor</property>
<property name="label" translatable="yes">Open terminal</property>
<property name="response_id">1</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_checkbutton1_toggled"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">Exit</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button2_clicked"/>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
strobon 0 Newbie Poster
well, i a bit desperate here....
so let me simplify what i mean,
i only need set a command to checkbutton1, so when we click button1
it will check if checkbutton is checked then it will run something like
popup message and if not checked nothing will happen
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.