📜  使用Python构建应用程序以搜索已安装的应用程序

📅  最后修改于: 2022-05-13 01:54:23.629000             🧑  作者: Mango

使用Python构建应用程序以搜索已安装的应用程序

先决条件 - Python中的 Tkinter

在本文中,我们将编写Python脚本来搜索 Windows 上已安装的应用程序并将其与 GUI 应用程序绑定。我们正在使用winapps模块来管理 Windows 上已安装的应用程序。

要安装模块,请在终端中运行以下命令:

下面是 GUI 的样子:-

winapps 模块中使用的方法

要打印已安装的应用程序,winapps 模块具有winapps.list_installed()方法。吨

Python3
# import modules
import winapps
 
# get each application with list_installed()
for item in winapps.list_installed():
    print(item)


Python3
for item in winapps.search_installed('chrome'):
    print(item)


Python3
# import modules
from tkinter import *
import winapps
 
# funtion to attach output
def app():
 
    for item in winapps.search_installed(e.get()):
        name.set(item.name)
        version.set(item.version)
        Install_date.set(item.install_date)
        publisher.set(item.publisher)
        uninstall_string.set(item.uninstall_string)
 
 
# object of tkinter
# and background set for grey
master = Tk()
master.configure(bg='light grey')
 
# Variable Classes in tkinter
name = StringVar()
version = StringVar()
Install_date = StringVar()
publisher = StringVar()
uninstall_string = StringVar()
 
 
# Creating label for each information
# name using widget Label
Label(master, text="Enter App name : ",
      bg="light grey").grid(row=0, sticky=W)
Label(master, text="Name : ",
      bg="light grey").grid(row=2, sticky=W)
Label(master, text="Version :",
      bg="light grey").grid(row=3, sticky=W)
Label(master, text="Install date :",
      bg="light grey").grid(row=4, sticky=W)
Label(master, text="publisher :",
      bg="light grey").grid(row=5, sticky=W)
Label(master, text="Uninstall string :",
      bg="light grey").grid(row=6, sticky=W)
 
 
# Creating lebel for class variable
# name using widget Entry
Label(master, text="", textvariable=name,
      bg="light grey").grid(row=2, column=1, sticky=W)
Label(master, text="", textvariable=version,
      bg="light grey").grid(row=3, column=1, sticky=W)
Label(master, text="", textvariable=Install_date,
      bg="light grey").grid(row=4, column=1, sticky=W)
Label(master, text="", textvariable=publisher,
      bg="light grey").grid(row=5, column=1, sticky=W)
Label(master, text="", textvariable=uninstall_string,
      bg="light grey").grid(row=6, column=1, sticky=W)
 
 
e = Entry(master, width=30)
e.grid(row=0, column=1)
 
# creating a button using the widget
b = Button(master, text="Show", command=app, bg="Blue")
b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5,)
 
mainloop()



输出:

为了搜索现有的应用程序,该模块具有search_installed('App_name')方法。

蟒蛇3

for item in winapps.search_installed('chrome'):
    print(item)


输出:

使用 Tkinter 在 Windows 中搜索应用程序

蟒蛇3

# import modules
from tkinter import *
import winapps
 
# funtion to attach output
def app():
 
    for item in winapps.search_installed(e.get()):
        name.set(item.name)
        version.set(item.version)
        Install_date.set(item.install_date)
        publisher.set(item.publisher)
        uninstall_string.set(item.uninstall_string)
 
 
# object of tkinter
# and background set for grey
master = Tk()
master.configure(bg='light grey')
 
# Variable Classes in tkinter
name = StringVar()
version = StringVar()
Install_date = StringVar()
publisher = StringVar()
uninstall_string = StringVar()
 
 
# Creating label for each information
# name using widget Label
Label(master, text="Enter App name : ",
      bg="light grey").grid(row=0, sticky=W)
Label(master, text="Name : ",
      bg="light grey").grid(row=2, sticky=W)
Label(master, text="Version :",
      bg="light grey").grid(row=3, sticky=W)
Label(master, text="Install date :",
      bg="light grey").grid(row=4, sticky=W)
Label(master, text="publisher :",
      bg="light grey").grid(row=5, sticky=W)
Label(master, text="Uninstall string :",
      bg="light grey").grid(row=6, sticky=W)
 
 
# Creating lebel for class variable
# name using widget Entry
Label(master, text="", textvariable=name,
      bg="light grey").grid(row=2, column=1, sticky=W)
Label(master, text="", textvariable=version,
      bg="light grey").grid(row=3, column=1, sticky=W)
Label(master, text="", textvariable=Install_date,
      bg="light grey").grid(row=4, column=1, sticky=W)
Label(master, text="", textvariable=publisher,
      bg="light grey").grid(row=5, column=1, sticky=W)
Label(master, text="", textvariable=uninstall_string,
      bg="light grey").grid(row=6, column=1, sticky=W)
 
 
e = Entry(master, width=30)
e.grid(row=0, column=1)
 
# creating a button using the widget
b = Button(master, text="Show", command=app, bg="Blue")
b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5,)
 
mainloop()

输出: