Hi i am trying to do a simple program for my school project, this is the first time i am using python as i am used to c# programming
I am using Window7, Is there ways in which I can press a button in a TK GUI and this directory be pop out ?
InitDir = "C:\AgmPlots"
As other stated, you need some (platform specific) program to "open" a directory.
The most platform-independent way could possibly be the webbrowser module. (Although it has web in its name, it opens my standard file manager with file:// URLs).
import webbrowser
And somewhere inside your event handler:
webbrowser.open ('file:///home/nobody') #your path here
Related
I am working on automating program that requires choosing file path.
After I click the browse button using code:
dlg.child_window(auto_id='btnBrwsBinFile').click()
browse window opens and freeze execution of code and I cannot control the popup window.
I have tried also different approach. I have edited text filed using code:
dlg['Edit'].set_text(path)
but then program do not see the path, it treats the field like it was never edited, like it was empty
I would like to ask if someone solved this issue before.
try:
dlg.child_window(title='btnBrwsBinFile').click_input()
pywinauto documentation:https://pywinauto.readthedocs.io/en/latest/code/pywinauto.findwindows.html
You can use UISpy.exe to get the title, class name
If I had a print() statement, for example:
print('https://www.google.com')
Is there a way to make a link clickable? And would the same apply for a file path, like this:
print('path/to/file')
What I need is a way to print a link/path to a terminal and then to be able to open it by clicking on it. Is this possible? If yes, how?
Python itself has nothing to do with this behavior- its functionality provided by your terminal emulator.
However, you can open a link programmatically in the browser within python using the builtin webbrowser module, for instance:
from webbrowser import open_new_tab
open_new_tab("https://www.google.com")
In some scenarios, this may be sufficient.
I am trying to create vi editor kind of app using python, that takes input from command line
and, provides option to save the typed text .So I need to use the save dialog box without using tkinter. How can I write python script that makes the call to windows save file dialog api
You can use pywin32
import win32ui
dlg = win32ui.CreateFileDialog(0)
dlg.SetOFNInitialDir(r'C:\Users\jezequiel\Desktop')
dlg.DoModal()
print(dlg.GetPathName())
I wanted to make a python 3 program that types something in another window, such as Google Chrome.
Is this possible, and if so, how?
This question is a little open ended, but it sounds like you want an http server. You can use either SimpleHTTPServer or make your own from scratch. A basic HelloWorld for using python3's http module is here. I used this simple guide to help me understand the basics of web servers in python. Hope this helps!
import pyautogui
searchbar = (x, y)
text_or_url = "hello word!"
pyautogui.click(searchbar)
pyautogui.typewrite(text_or_url)
pyautogui.typewrite([Enter])
Use pywinauto lib
It is very easy.
For example you have opened notepad window and opened 'Save as' dialog and want to type filename:
from pywinauto import application
app = application.Application()
app.connect(title='test1.txt - Notepad')
app.SaveAs.Edit1.type_keys("C:\\test2.txt")
Use pywinauto lib
filePath.set_text('D:\\aa.txt')
inpuMsg.type_keys('D:\\aa.txt')
set_text
type_keys
So my App needs to be able to open a single webpage(and it must be from the internet and not saved) in it, and specifically I'd like to use the Tkinter GUI toolkit since it's the one i'm most comfortable with. On top of that though, I'd like to be able to generate events in the window(say a mouse click) but without actually using the mouse. What's a good method to go about this?
EDIT: I suppose to clarify this a bit, I need a way to load a webpage, or maybe even a specific java applet into a tkinter widget or window. Or if not that perhaps another method to do this where I can generate mouse and keyboard events without using either the mouse of the keyboard.
If you want it to be opened inside your GUI use Bryans suggestion, if you just want to open a webpage you can use:
import webbrowser
webbrowser.open("page.html")
Tkinter does not have a widget that can render a web page.
So i found this module named pywebview
pip install pywebview
sample code:-
import webview
webview.create_window('duckduckgo', 'https://www.duckduckgo.com')
webview.start() #this will open the webpage in a new window
You should use pywebview it is very easy only code three lines .
I used it but in my case it didn't work everywhere. Comment and let me know if it works for you.
The best option that works everywhere is PyQt's QtWebview module. You might run into one problem that is to rename the window, so here is the solution
web.setWindowTitle(title)
You can use all the functions as it is but just replace window or self with web like the above code.