# Input function writing on wrong line

**URL:** <https://discourse.slicer.org/t/input-function-writing-on-wrong-line/25651>\
**Category:** Support\
**Created:** [October 12, 2022, 9:53am UTC](https://discourse.slicer.org/t/input-function-writing-on-wrong-line/25651 "2022-10-12T09:53:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hourglassnam](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hourglassnam/32/11796_2.png) [@hourglassnam](https://discourse.slicer.org/u/hourglassnam)\
**Post date:** [October 12, 2022, 9:53am UTC](https://discourse.slicer.org/t/input-function-writing-on-wrong-line/25651/1 "2022-10-12T09:53:04Z")

</div>

Hello, Slicer community!

I was trying to make the python process wait for me while I manually edit the segmentation.

I thought of using the input function for this.  
But somehow, the python interacter keep makes me to write on wrong line and the function would not work properly…

I tested the same script on VS code and it worked as it supposed to.  
So I do not understand why slicer is making me write on wrong line.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/d/8d2e71222c006711a35cb6828e721b0c985583b9.jpeg)

 ![KakaoTalk_Photo_2022-10-12-15-46-19](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/c/9c084f8466a05c873e8cf8207cc1456a33ad67bf.jpeg)

Can anyone give me advice on why this problem may occur and how to I can solve this?  
below is my script and thank you always for your help.

```auto
import os
import sys

def moveOn():
	toPass = ["y", "Y"]
	while True:
		try:
			value = input("Do you want to move on?(Y/N) : ")
		except ValueError:
			print("Sorry, I didn't understand that.")
			return moveOn()
		if value not in toPass:
			print("Sorry, you typed wrong value.")
			return moveOn()
		else:
			return value

nrrdDir = "F:/inputTesting"
nrrdList = [file for file in os.listdir(nrrdDir) if file.endswith(r'.nrrd')]
for volFile in nrrdList:
	volName = str(volFile).strip(".nrrd")
	volDir = nrrdDir + "/" + volFile
	print(" ____" + volName + " Polishing...\n")
	value = moveOn()
	print("If this is printed, then input worked")

```

---

<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 19, 2022, 9:17pm UTC](https://discourse.slicer.org/t/input-function-writing-on-wrong-line/25651/2 "2022-10-19T21:17:38Z")

</div>

Showing the user some messages on some text console in a GUI application would be highly unusual and inconvenient for users. Instead, you can quickly create a nice and convenient GUI in Qt designer. See for example [this tutorial](https://github.com/PerkLab/PerkLabBootcamp/blob/master/Doc/day3_2_SlicerProgramming.pptx). You can put a Segment Editor widget inside your module, so your users don’t need to switch to a different module during segmentation. Having your python script in a Slicer module also takes care of selecting inputs, outputs, installation, distribution to users, updates, etc.

If you don’t need very smooth user experience just some very quick way to run a python script somewhat interactively, then you can add a button anywhere on the GUI, for example in the status bar, and continue with the processing when the user clicked the button. For example:

```python
def onNextStep():
    print("Editing completed.")

nextStepButton = qt.QPushButton("Finish segmentation")
slicer.util.mainWindow().statusBar().insertPermanentWidget(0, nextStepButton)
nextStepButton.connect('clicked()', onNextStep)

# To remove the button:
# slicer.util.mainWindow().statusBar().removeWidget(nextStepButton)

```

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/3/e3ce1f01f12f68a6316939a2518a62db1b0f7db2.png)

---

<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 21, 2022, 12:12pm UTC](https://discourse.slicer.org/t/input-function-writing-on-wrong-line/25651/3 "2022-10-21T12:12:01Z")

</div>

About the original issue of the unexpected behavior of the console: I’ve [submitted a fix for the issue](https://github.com/commontk/CTK/pull/1045), it should be integrated into the Slicer Preview Release within a few days. I would still recommend to use buttons, widgets, etc. on a module GUI to communicate with end users, instead of via messages in a text console.

---

<div class="post-metadata">

**Author:** ![hourglassnam](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hourglassnam/32/11796_2.png) [@hourglassnam](https://discourse.slicer.org/u/hourglassnam)\
**Post date:** [November 9, 2022, 6:29am UTC](https://discourse.slicer.org/t/input-function-writing-on-wrong-line/25651/4 "2022-11-09T06:29:48Z")

</div>

This is so awesome!! 😆  
I did tried to make a button but just could not figure out how to make it work properly!  
So thank you so much for providing this awesome script!!  
This is way better than what I have been doing!!  
And thank you for fixing the console as well!!!
