Here is a part of the script that I am using and it is working correctly.
try:
(sshin1, sshout1, ssherr1) = proxy_client.exec_command(mycommand)
print sshout1.read()
mytext=sshout1.read()
print type(mytext)
except:
print "error while executing the command on remote host"
But when I add this line, at the end, it creates a pop-up window with "Say Hello" title but does not show the mytext contents.
tkMessageBox.showinfo("Say Hello", mytext)
The print statement in the try block will display the output to the terminal. How do I show the same output in a pop-up window?
update:
The text shown in the pop-up window can not be copied and pasted to some other application like notepad. Is there any easy way?
I just had to comment out the print statement. For some reason the .read() output was getting destroyed after printing.
#print sshout1.read()
Related
I am writing a console program using python.
As you must be knowing, when a program is running and then a user scrolls up the command window, when the program prints something the window itself scrolls down to the end.
But when I do this print("\033[A\033[A") to remove the last printed line in the command prompt, it does not scroll down to the bottom and remove the last printed line but instead clears up the last line on the part of the screen that's visible to me.
What should I do to solve this?
Please help. Thank you!
I am on windows 10
I'm sorry if this question has already been answered, but I couldn't find anything on here (except this one which hasn't been answered: link and one that doesn't quite answer the question i'm asking link
I'm creating a button with ipywidgets, but the script doesn't wait for the button to be clicked. Here's a sample of the code/what I'm trying to achieve:
button = widgets.Button(description = "Click")
output = widgets.Output()
display(button, output)
def on_button_clicked(b):
with output:
print("button clicked")
button.on_click(on_button_clicked)
print("Python is ignoring you")
If I run this, I'll just get "Python is ignoring you" before I click the button. I want it to display the button, wait for the person to click it, and only then execute the rest ("Python is ignoring you").
Does anyone have an idea of how I can make python wait for the button to be clicked?
Would appreciate any help! Thanks
I never used the ipywidgets, but the problem is on the last line
you're telling python to print "Python is ignoring you" and python is doing it.
It will not wait for the user to click the button,
because the print statement is out the function "on_button_clicked".(or any)
So just Put it in the function. (That print Statement)
I would appreciate some thoughts on a problem at hand that I've been trying to solve for 1-2 days.
I am running a Python script with Selenium 2.53.6 on FireFox 49.0.1. The script is supposed to click a series of document-download links on a page (I have set the browser to automatically download these file types instead of opening them). Upon clicking, one of the following two events may unfold:
A pop-up window appears. A button on the pop-up window needs to be clicked to close it before the document is downloaded.
A blank pop-up appears momentarily before it disappears on its own when the document download begins.
Here's an excerpt of the script that is written to handle the events above:
file_link = tr.find_element_by_xpath('td[5]/a')
file_link.click()
time.sleep(7) # Allows the blank pop-up to disappear automatically under Event2
agree_button = None
# Checks for the pop-up window
try:
print "Step 1"
driver.switch_to.window(driver.window_handles[1])
print "Step 2" # SCRIPT STOPS RUNNING HERE
agree_button = driver.find_element_by_xpath('//input[#value="Agree and proceed"]')
print "Popup found"
except:
driver.switch_to.window(driver.window_handles[0])
# Clicks the button if the pop-up window is found
if agree_button is not None:
agree_button.click()
print "Button clicked"
The trouble surfaces when there's high latency in the network for Event 2. Under normal circumstances, the blank pop-up disappears almost instantaneously and the download begins immediately after. However, if the network is slow, the blank pop-up may persist beyond the allocated 7 seconds and that resulted in the script running into "Step 2" before the pop-up window disappears.
Strangely, at this point the script doesn't continue on to look for the agree_button. If it does, then that would have triggered the exception and I would be able to revert back to the original window to resume the steps. The script just stalls and does nothing it seems.
Thanks in advance for your time guys!
You need to keep on waiting until the pop-up disappears. One way you might do this is making below changes in your code:
file_link = tr.find_element_by_xpath('td[5]/a')
file_link.click()
time.sleep(7) # Allows the blank pop-up to disappear automatically under Event2
agree_button = None
# Checks for the pop-up window
try:
print "Step 1"
driver.switch_to.window(driver.window_handles[1])
print "Step 2" # SCRIPT STOPS RUNNING HERE
while True:
agree_button = driver.find_element_by_xpath('//input[#value="Agree and proceed"]')
if agree_button is not None:
break
else:
sleep(7)
print "Popup found"
except:
driver.switch_to.window(driver.window_handles[0])
# Clicks the button if the pop-up window is found
if agree_button is not None:
agree_button.click()
print "Button clicked"
Here's the code I'm using on Skulpt:
print('Intro text')
user_input = input('Prompt the user: ')
print(user_input)
The first thing that happens is an empty dialog box pops up, i.e. without the prompt. Only once something is entered in the dialog box does everything print to the output window:
Dialog box with empty text output window
Does anyone have any ideas?
(Right now, I'm using a workaround using time.sleep() before each input() -- ugh)
I have a wxPython script, which executes a process after clicking the button and display the process output in a wx.StaticText.
The problem is when I want to re-execute the process , and so I click on button and the old result is displayed (output of the first process); this old result is still displayed on the window, while I have added an instruction that normally will hide it:
Here is lines of my code:
def OnButton(self, e):
if self.res=="udpscan":
self.resultat1.SetLabel("")
ipad=self.ipadd.GetValue()
fromm=self.fr.GetValue()
too=self.to.GetValue()
ifc=self.intf.GetValue()
if len(ipad) <1 or len(too) < 1 or len(fromm) <1 or len(ifc) < 1:
wx.MessageBox('Please enter missing values','error',wx.OK)
else:
sp=subprocess.Popen(['python','udp_portscan.py',ifc,ipad,fromm,too],stdout=subprocess.PIPE)
text=sp.stdout.readlines()
text="".join(text)
self.resultat1.SetLabel(text)
I have tried to add other intructions to hide it but same problem.
Can you help me please. Thank you
sp seems to store all the previous output in sp.stdout.
There might be a way to clear it using .kill():
sp=subprocess.Popen(['python','udp_portscan.py',ifc,ipad,fromm,too],stdout=subprocess.PIPE)
text=sp.stdout.readlines()
sp.kill()