def bit_dir_open(self, gs):
"""Open filedialog when Select Location of Files button selected."""
self.bit_dir_path = filedialog.askdirectory()
gs.bit_path = self.bit_dir_path
self.bit_dir_var.set(self.bit_dir_path)
python类askdirectory()的实例源码
def archive_dir_open(self, gs):
"""Open filedialog when Select Archive Destination button selected."""
self.archive_dir_path = filedialog.askdirectory()
gs.archive_path = self.archive_dir_path
self.archive_dir_var.set(self.archive_dir_path)
def diropenbox(msg=None
, title=None
, default=None
):
"""
A dialog to get a directory name.
Note that the msg argument, if specified, is ignored.
Returns the name of a directory, or None if user chose to cancel.
If the "default" argument specifies a directory name, and that
directory exists, then the dialog box will start with that directory.
"""
title=getFileDialogTitle(msg,title)
localRoot = Tk()
localRoot.withdraw()
if not default: default = None
f = tk_FileDialog.askdirectory(
parent=localRoot
, title=title
, initialdir=default
, initialfile=None
)
localRoot.destroy()
if not f: return None
return os.path.normpath(f)
#-------------------------------------------------------------------
# getFileDialogTitle
#-------------------------------------------------------------------
def setUp(self):
self.o_aof = filedialog.askopenfilename
self.o_ad = filedialog.askdirectory
self.o_input = builtins.input
self.settings = Settings()
def tearDown(self):
filedialog.askopenfilename = self.o_aof
filedialog.askdirectory = self.o_ad
builtins.input = self.o_input
def test_get_path_gui(self):
# Setup
filedialog.askdirectory = lambda title: 'test_path'
# Test
self.assertEqual(ask_path_gui('test message', self.settings, get_file=False), 'test_path')
def test_no_path_raises_fr(self):
# Setup
filedialog.askdirectory = lambda title: ''
# Test
self.assertFR("Path selection aborted.", ask_path_gui, 'test message', self.settings, False)
def ask_path_gui(prompt_msg: str,
settings: Union['Settings', 'nhSettings'],
get_file: bool = False) -> str:
"""Prompt (file) path with Tkinter / CLI prompt.
:param prompt_msg: Directory selection prompt
:param settings: Settings object
:param get_file: When True, prompts for path to file instead of directory
:return: Selected directory / file
"""
try:
if settings.disable_gui_dialog:
raise _tkinter.TclError
root = Tk()
root.withdraw()
if get_file:
file_path = filedialog.askopenfilename(title=prompt_msg)
else:
file_path = filedialog.askdirectory(title=prompt_msg)
root.destroy()
if not file_path:
raise FunctionReturn(("File" if get_file else "Path") + " selection aborted.")
return file_path
except _tkinter.TclError:
return ask_path_cli(prompt_msg, get_file)
def open_folder(self):
self.button_run['state'] = 'disabled'
self.top_dir = filedialog.askdirectory(initialdir='.')
self.label_path['text'] = 'Looking for images to optimize... Please, wait'
self._start_count_images()
def open_folder(self):
self.button_run['state'] = 'disabled'
self.top_dir = filedialog.askdirectory(initialdir='.')
self.label_path['text'] = 'Looking for images to optimize... Please, wait'
self._start_count_images()
def diropenbox(msg=None
, title=None
, default=None
):
"""
A dialog to get a directory name.
Note that the msg argument, if specified, is ignored.
Returns the name of a directory, or None if user chose to cancel.
If the "default" argument specifies a directory name, and that
directory exists, then the dialog box will start with that directory.
"""
title=getFileDialogTitle(msg,title)
boxRoot = Tk()
boxRoot.withdraw()
if not default: default = None
f = tk_FileDialog.askdirectory(
parent=boxRoot
, title=title
, initialdir=default
, initialfile=None
)
boxRoot.destroy()
if not f: return None
return os.path.normpath(f)
#-------------------------------------------------------------------
# getFileDialogTitle
#-------------------------------------------------------------------
guiscrape.py 文件源码
项目:Python-Journey-from-Novice-to-Expert
作者: PacktPublishing
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def save():
if not config.get('images'):
_alert('No images to save')
return
if _save_method.get() == 'img':
dirname = filedialog.askdirectory(mustexist=True)
_save_images(dirname)
else:
filename = filedialog.asksaveasfilename(
initialfile='images.json',
filetypes=[('JSON', '.json')])
_save_json(filename)
def button_browse_callback_pfo_input(self):
filename = tkFileDialog.askdirectory()
self.entry_pfo_input.delete(0, tk.END)
self.entry_pfo_input.insert(0, filename)
def button_browse_callback_pfo_output(self):
filename = tkFileDialog.askdirectory()
self.entry_pfo_output.delete(0, tk.END)
self.entry_pfo_output.insert(0, filename)
def directoryBox(self, title=None, dirName=None):
self.topLevel.update_idletasks()
options = {}
options['initialdir'] = dirName
options['title'] = title
options['mustexist'] = False
fileName = filedialog.askdirectory(**options)
if fileName == "":
return None
else:
return fileName
def hashcatdownloadfunc(): #GIT CLONES AND MAKE-BUILDs HASHCAT!
import os, webbrowser, time
from tkinter import filedialog
from tkinter import Tk
os.system("clear")
print("""\033[0;33;48m
a a
aaa aaa
aaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaa
aaaaafaaaaaaafaaaaaa
aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaa
aaaaaaa aaaaaaa
aaaaaaaaaaaaaa
a aaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaa
??? ??? ?????? ??????????? ??? ??????? ?????? ?????????
??? ?????????????????????? ????????????????????????????
??????????????????????????????????? ???????? ???
??????????????????????????????????? ???????? ???
??? ?????? ?????????????? ?????????????? ??? ???
??? ?????? ?????????????? ??? ?????????? ??? ???
\033[0;39;48m
""")
if input("\033[1;39;48mDownload and setup hashcat for GPU-WPA cracking? [y/n] >> ").lower().startswith("y"):
os.system("clear")
print("\nWhere would you like hashcat installed?")
input("\n|MENU|POST_CRACK|GPU|HASHCAT_DOWNLOAD|(Please delete any older versions and press enter to choose directory) >>")
global hashpath
Tk().withdraw()
hashpath = filedialog.askdirectory()
hashpath = str(hashpath)
print("\nA browser window will now open. ALT+TAB back to the terminal")
time.sleep(3)
webbrowser.open("https://hashcat.net/")
#print("Please right-click and copy/paste link location on the button next to hashcat binaries")
downloadpath = input("\nPlease paste the URL/ADDRESS/LINK-LOCATION of the hashcat binaries download button EG:https://hashcat.net/files/hashcat-3.6.0.7z \033[1;31;48m~# \033[0;39;48m")
os.system("sudo apt install p7zip p7zip-full -y;cd %s;wget %s;7z x hashcat-*;git clone https://github.com/hashcat/hashcat-utils.git;cd hashcat-utils/src/;make" %(hashpath, downloadpath))
#os.system("cd %s;git clone https://github.com/hashcat/hashcat.git;cd hashcat/;git submodule update --init;make;cd ..;git clone https://github.com/hashcat/hashcat-utils.git;cd hashcat-utils/src/;make" %(hashpath))
os.system("\necho '\033[1;32;48m[+] \033[1;39;48mHashcat is now ready to use, it will be inside the folder you chose \033[0;39;48m' ")
os._exit(1)
else:
title()
def drifunc(): #Installs downloaded drivers
import os
from tkinter.filedialog import askopenfilename, Tk as snak
snak().withdraw()
def Nvidia():
os.system("clear")
global nvenc
path = input("Please select where the NVIDIA driver file is located. Press enter (you may have to answer yes to some options) \033[1;31;48m~# \033[0;39;48m")
nvenc = askopenfilename()
nvenc = str(nvenc)
os.system("clear")
input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|NVIDIA|(Please remove any previous drivers/driver downloads and hit enter) \033[1;31;48m~# \033[0;39;48m")
os.system("cd %s;sudo ./NVIDIA-Linux*" %(nvenc))
print("echo NVIDIA driver is installed!")
print("now reboot, if you see any error, please head to: 'https://goo.gl/f1GU1F'")
def AMD():
os.system("clear")
from tkinter import filedialog
from tkinter import Tk
global AMDlol
AMDlol = input("Please select the folder where the AMD driver tar.xz file is located. Press enter \033[1;31;48m~# \033[0;39;48m")
AMDlol = filedialog.askdirectory()
AMDlol = str(AMDlol)
os.system("clear")
input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|AMD|(Please remove any previous drivers/driver downloads and hit enter) \033[1;31;48m~# \033[0;39;48m")
os.system("cd %s;tar -Jxvf amdgpu-pro*;cd amdgpu-pro*;./amdgpu-pro-install -y" %(AMDlol))
print("echo AMD driver is installed!")
print("now reboot, if you see any error, type: 'amdgpu-pro-uninstall' and reboot.")
print("""
??????? ???????????????????? ?????? ??? ??? ??????? ??????? ?????? ?????????????????? ????????
???????? ??????????????????????????????? ??? ?????????????????????? ???????????????????????????
????????? ??????????? ??? ??????????? ??? ??? ????????????????? ????????? ????????????????
????????????????????? ??? ??????????? ??? ??? ?????????????????? ?????????? ????????????????
?????? ?????????????? ??? ??? ??????????????????? ??????????? ?????? ??????? ??????????? ???????????
?????? ????????????? ??? ??? ??????????????????? ??????? ??? ?????? ????? ??????????? ???????????
""")
print("This is the driver installation screen. Your options are:")
print("\n\n\033[1;35;48mType [1] - Install the NVIDIA-LINUX driver for Hashcat (NVIDIA GTX 900,10 Series)")
print("\033[1;34;48mType [2] - Install the AMDGPU-PRO driver to use Hashcat with an AMD gpu (MOST GPUs, check hashcat.net)")
sel = input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|(Type number) >>")
if sel == "":
drifunc()
if sel == "1":
Nvidia()
if sel == "2":
AMD()
def hashcatdownloadfunc(): #GIT CLONES AND MAKE-BUILDs HASHCAT!
import os, webbrowser, time
from tkinter import filedialog
from tkinter import Tk
os.system("clear")
print("""
a a
aaa aaa
aaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaa
aaaaafaaaaaaafaaaaaa
aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaa
aaaaaaa aaaaaaa
aaaaaaaaaaaaaa
a aaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaa
??? ??? ?????? ??????????? ??? ??????? ?????? ?????????
??? ?????????????????????? ????????????????????????????
??????????????????????????????????? ???????? ???
??????????????????????????????????? ???????? ???
??? ?????? ?????????????? ?????????????? ??? ???
??? ?????? ?????????????? ??? ?????????? ??? ???
""")
if input("Download and setup hashcat for GPU-WPA cracking? [y/n] >> ").lower().startswith("y"):
os.system("clear")
print("\nWhere would you like hashcat installed?")
input("\n|MENU|POST_CRACK|GPU|HASHCAT_DOWNLOAD|(Please delete any older versions and press enter to choose directory) >>")
global hashpath
Tk().withdraw()
hashpath = filedialog.askdirectory()
hashpath = str(hashpath)
print("\nA browser window will now open. ALT+TAB back to the terminal")
time.sleep(3)
webbrowser.open("https://hashcat.net/")
#print("Please right-click and copy/paste link location on the button next to hashcat binaries")
downloadpath = input("\nPlease paste the URL/ADDRESS/LINK-LOCATION of the hashcat binaries download button EG:https://hashcat.net/files/hashcat-3.6.0.7z ~# ")
os.system("sudo apt install p7zip p7zip-full -y;cd %s;wget %s;7z x hashcat-*;git clone https://github.com/hashcat/hashcat-utils.git;cd hashcat-utils/src/;make" %(hashpath, downloadpath))
#os.system("cd %s;git clone https://github.com/hashcat/hashcat.git;cd hashcat/;git submodule update --init;make;cd ..;git clone https://github.com/hashcat/hashcat-utils.git;cd hashcat-utils/src/;make" %(hashpath))
os.system("\necho '[+] Hashcat is now ready to use, it will be inside the folder you chose ' ")
os._exit(1)
else:
title()
def drifunc(): #Installs downloaded drivers
import os
from tkinter.filedialog import askopenfilename, Tk as snak
snak().withdraw()
def Nvidia():
os.system("clear")
global nvenc
path = input("Please select where the NVIDIA driver file is located. Press enter (you may have to answer yes to some options) ~# ")
nvenc = askopenfilename()
nvenc = str(nvenc)
os.system("clear")
input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|NVIDIA|(Please remove any previous drivers/driver downloads and hit enter) ~# ")
os.system("cd %s;sudo ./NVIDIA-Linux*" %(nvenc))
print("echo NVIDIA driver is installed!")
print("now reboot, if you see any error, please head to: 'https://goo.gl/f1GU1F'")
def AMD():
os.system("clear")
from tkinter import filedialog
from tkinter import Tk
global AMDlol
AMDlol = input("Please select the folder where the AMD driver tar.xz file is located. Press enter ~# ")
AMDlol = filedialog.askdirectory()
AMDlol = str(AMDlol)
os.system("clear")
input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|AMD|(Please remove any previous drivers/driver downloads and hit enter) ~# ")
os.system("cd %s;tar -Jxvf amdgpu-pro*;cd amdgpu-pro*;./amdgpu-pro-install -y" %(AMDlol))
print("echo AMD driver is installed!")
print("now reboot, if you see any error, type: 'amdgpu-pro-uninstall' and reboot.")
print("""
??????? ???????????????????? ?????? ??? ??? ??????? ??????? ?????? ?????????????????? ????????
???????? ??????????????????????????????? ??? ?????????????????????? ???????????????????????????
????????? ??????????? ??? ??????????? ??? ??? ????????????????? ????????? ????????????????
????????????????????? ??? ??????????? ??? ??? ?????????????????? ?????????? ????????????????
?????? ?????????????? ??? ??? ??????????????????? ??????????? ?????? ??????? ??????????? ???????????
?????? ????????????? ??? ??? ??????????????????? ??????? ??? ?????? ????? ??????????? ???????????
""")
print("This is the driver installation screen. Your options are:")
print("\n\nType [1] - Install the NVIDIA-LINUX driver for Hashcat (NVIDIA GTX 900,10 Series)")
print("Type [2] - Install the AMDGPU-PRO driver to use Hashcat with an AMD gpu (MOST GPUs, check hashcat.net)")
sel = input("\n|MENU|POST_CRACK|GPU|DRIVER_INSTALL|(Type number) >>")
if sel == "":
drifunc()
if sel == "1":
Nvidia()
if sel == "2":
AMD()
def hashcatdownloadfunc(): #GIT CLONES AND MAKE-BUILDs HASHCAT!
import os, webbrowser, time
from tkinter import filedialog
from tkinter import Tk
os.system("clear")
print("""\033[0;33;48m
a a
aaa aaa
aaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaa
aaaaafaaaaaaafaaaaaa
aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaa
aaaaaaa aaaaaaa
aaaaaaaaaaaaaa
a aaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaaaa
aaa aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaa
??? ??? ?????? ??????????? ??? ??????? ?????? ?????????
??? ?????????????????????? ????????????????????????????
??????????????????????????????????? ???????? ???
??????????????????????????????????? ???????? ???
??? ?????? ?????????????? ?????????????? ??? ???
??? ?????? ?????????????? ??? ?????????? ??? ???
\033[0;39;48m
""")
if input("\033[1;39;48mDownload and setup hashcat for GPU-WPA cracking? [y/n] >> ").lower().startswith("y"):
os.system("clear")
print("\nWhere would you like hashcat installed?")
input("\n|MENU|POST_CRACK|GPU|HASHCAT_DOWNLOAD|(Please delete any older versions and press enter to choose directory) >>")
global hashpath
Tk().withdraw()
hashpath = filedialog.askdirectory()
hashpath = str(hashpath)
print("\nA browser window will now open. ALT+TAB back to the terminal")
time.sleep(3)
webbrowser.open("https://hashcat.net/")
#print("Please right-click and copy/paste link location on the button next to hashcat binaries")
downloadpath = input("\nPlease paste the URL/ADDRESS/LINK-LOCATION of the hashcat binaries download button EG:https://hashcat.net/files/hashcat-3.6.0.7z \033[1;31;48m~# \033[0;39;48m")
os.system("sudo apt install p7zip p7zip-full -y;cd %s;wget %s;7z x hashcat-*;git clone https://github.com/hashcat/hashcat-utils.git;cd hashcat-utils/src/;make" %(hashpath, downloadpath))
#os.system("cd %s;git clone https://github.com/hashcat/hashcat.git;cd hashcat/;git submodule update --init;make;cd ..;git clone https://github.com/hashcat/hashcat-utils.git;cd hashcat-utils/src/;make" %(hashpath))
os.system("\necho '\033[1;32;48m[+] \033[1;39;48mHashcat is now ready to use, it will be inside the folder you chose \033[0;39;48m' ")
os._exit(1)
else:
title()