# How to press qtButton?

**URL:** https://discourse.slicer.org/t/how-to-press-qtbutton/13947
**Category:** Development
**Tags:** vtk, python, qt
**Created:** [October 9, 2020, 1:56am UTC](https://discourse.slicer.org/t/how-to-press-qtbutton/13947 "2020-10-09T01:56:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)
#### Post date: [October 9, 2020, 1:56am UTC](https://discourse.slicer.org/t/how-to-press-qtbutton/13947/1 "2020-10-09T01:56:18Z")

</div>

Hi  
today I’m trying to press a button by code.

and i know the name of the object is: setupLightkitButton  
i all ready try this:

> > > qt.QPushButton(‘setupLightkitButton’).click()  
> > > qt.QPushButton(‘setupLightkitButton’).animateClick()  
> > > qt.QPushButton(‘setupLightkitButton’).animateClick(True)  
> > > light=qt.QPushButton(‘setupLightkitButton’)  
> > > light.clicked(True)  
> > > light.checked

---

<div class="post-metadata">

### Author: ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)
#### Post date: [October 9, 2020, 2:07am UTC](https://discourse.slicer.org/t/how-to-press-qtbutton/13947/2 "2020-10-09T02:07:03Z")

</div>

the only way I found was by edit the UI

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [October 9, 2020, 2:22am UTC](https://discourse.slicer.org/t/how-to-press-qtbutton/13947/3 "2020-10-09T02:22:23Z")

</div>

You should never use a module’s widget class from another module. See [Scripting and module development tutorial](https://github.com/PerkLab/PerkLabBootcamp/blob/master/Doc/day3_2_SlicerProgramming.pptx?raw=true) on the [training page](https://www.slicer.org/wiki/Documentation/Nightly/Training#PerkLab.27s_Slicer_bootcamp_training_materials) for details.

Instead, you can call methods implemented in the other module’s logic. In some experimental modules developers may work quick-and-dirty and put logic that could be useful for other modules in the widget. In this case you can either fix that module (move the useful code part into the module’s logic where you can access it from your own module) or just copy-paste the code into your module.

In this specific case, Lights module in Sandbox extension is implemented relatively cleanly: the function that is launched when `setupLightKitButton` is clicked (`onSetupLighkit`) calls the `setLightkitInView` function in the logic. So, in your module, you don’t need to deal with the Light module’s widget, just access its logic (or instantiate a new LightsLogic class) and use it.

---

<div class="post-metadata">

### Author: ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)
#### Post date: [October 9, 2020, 7:24pm UTC](https://discourse.slicer.org/t/how-to-press-qtbutton/13947/4 "2020-10-09T19:24:14Z")

</div>

thanks for the PowerPoint it gives me a better understanding.
