python pyautogui module are not support bangla text - python-3.x

Here is my python code. I am trying to write something in Bangla text using pyautoGUI but unfortunately, it's not working.
import time
import pyautogui
time.sleep(2)
text = "হ্যালো,"
pyautogui.typewrite(text)

Pyautogui doesn't seem to allow some characters without giving a Unicode hex string but I found an easier way by putting it in your clipboard.
import pyautogui
import pyperclip
import time
time.sleep(5)
# Store our string to the clipboard
pyperclip.copy("হ্যালো")
# Hotkey the paste command
pyautogui.hotkey("ctrl", "v")
This works about the same as typewrite just using a paste command instead of sending it like a keyboard (one charachter at a time)
# Output to typed
হ্যালো

Related

Pyperclip does not paste until entire code was run

I am trying to use pyperclip (1.8.2) on ubuntu (20), and it seems like the pasting only occurs once all the script has finished being executed. Moreover, pasting into a program seems to freeze that program (chrome for example).
import time
import pyperclip
pyperclip.copy('Hello, world!')
time.sleep(20)
# Paste anywhere, it will only appear after the 20 seconds are over.
What is the reason for this ? Is there a way to make this work (paste anywhere without delay) ?

Python Tkinter: Run python script when click button_widget of tkinter and keep value from return variables

I am new with GUI programming in Python 3.x with Tkinter.
I have prepared a GUI where user needs to select options (using OptionMenu widget) and after selection press button to run the final program.
I have saved the user selected data into variables in that GUI program.
But don't know what should I do next...
What I want:
That GUI should be hidden or End after pressing the button.
Run another python script and use those saved variables from that GUI in my script.
How it can be done in python.
You can save your data in another file in order to use it in other script with pickle module.
To save you can do a list with all the variables you want:
import pickle
with open('doc_name.txt','wb') as a:
pickle.dump(saved_variable_list,a)
And in another python script you can use that list of variables:
import pickle
with open('doc_name.txt','rb') as a:
saved_variable_list = pickle.load(a)
Finally to close your GUI you can use the 'destroy' command:
root.destroy()

How do i change the console title of a python script like console.title in c#

Is there a way to change title of a console based py program? so when i convert it to exe it'd show as "Test - v.1.5"
without using tkinter, kivy etc
found it
import os
os.system("title XYZ")

How to select cell to run when using Jupyter when running it in VSCode?

I like the way Jupyter extension is built on VSCode, but I haven't get it to run a cell of my choise.
My question is: Is there a way to select which line gets executed or is it always the last in the file?
Right now I just put each output providing cell to separate file and import required features, but quick iterative experiments would be handy just to quickly write on the same file.
It looks like #%% begins a cell so there are two ways of doing this I think:
#%%
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
#%%
x = np.linspace(0, 20, 100)
plt.plot(x, np.sin(x))
plt.show()
and you can run each cell separately (or line - wherever you place the #%%) Run cell will pop up above the line you put this on.
Or install code-runner: code-runner. For more info see here: Jupyter-IPython and here Getting Started
EDIT: Just found another way from the last hyperlink:
Open a python file
Select a line or a block of code
From the command palette (cmd+shift+p) select the command Jupyter: Run selection/line
The results will be displayed on the right hand side
A status bar will appear with the name and status of the kernel

Making Python text green and using Spinning cursor - Newbies questions

I want to make my Python script file,when I "announce" something to the user, to be green like this:
How can this be done?I saw a script using this with sys.stdout.write but I dont understand how to use it, Im using a simple "print" commands..
Also, I would like to have the Spinning cursor spin as long as this command runs and only stops when this command stops(finishes):
print('running network scan')
output = subprocesss.check_output('nmap -sL 192.168.1.0/24',shell=True)
print('Done')
Any way to do that (unknown time until task is done)?
Im using a code suggested by nos here:
Spinning Cursor
So, about getting the terminal color to be green, there is a neat package called colorama that generally works great for me. To check whether the process is running or not, I would recommend using Popen instead of check_output, since the latter does not allow you to communicate with the process as far as I know. But you need to since you want to know if your subprocess is still running. Here is a little code example that should get you running:
import subprocess
import shlex
import time
import sys
import colorama
def spinning_cursor():
"""Spinner taken from http://stackoverflow.com/questions/4995733/how-to-create-a-spinning-command-line-cursor-using-python/4995896#4995896."""
while True:
for cursor in '|/-\\':
yield cursor
# Create spinner
spinner = spinning_cursor()
# Print and change color to green
print(colorama.Fore.GREEN + 'running network scan')
# Define command we want to run
cmd = 'your command goes here'
# Split args for POpen
args=shlex.split(cmd)
# Create subprocess
p = subprocess.Popen(args,stdout=subprocess.PIPE)
# Check if process is still running
while p.poll()==None:
# Print spinner
sys.stdout.write(spinner.next())
sys.stdout.flush()
sys.stdout.write('\b')
print('Done')
# Grab output
output=p.communicate()[0]
# Reset color (otherwise your terminal is green)
print(colorama.Style.RESET_ALL)

Resources