Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to write a gadget to open a folder with wxPython

Shulou Source: shulou.com Published: 2022-06-01 11:31:43 09月13日 Update

This article introduces the knowledge of "how to write a gadget to open a folder with wxPython". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Configuration file

Config.py, the code is as follows

# coding=utf-8

Folder_config = {

U'Movie: "D:\\ Movie"

U' Game': "D:\\ Game"

}

The configuration here should be filled in according to your actual folder directory, using\ instead of\.

Do not add u in front of the folder path, or you will get an error. The string of 2.7 is a real headache.

Main program file

Openfolder.py, the code is as follows

# coding=utf-8

Import wx

Import os

From config import folder_config

Def clickbtn (event):

Checkindex = cl.GetChecked ()

For index in checkindex:

Name = cl.GetString (index)

Command = "explorer {folder}" .format (

Folder=folder_ config [name])

# first decode in utf-8, then encode in GBK

Command = command.decode (

'utf-8') .encode (' GBK')

Os.system (command)

Cl.Check (index, False)

App = wx.App ()

Window = wx.Frame (None, title=u "first program"

Size= (350,400)

Panel = wx.Panel (window)

B = wx.Button (panel, 10, u "open", (200,20))

Panel.Bind (wx.EVT_BUTTON, clickbtn, b)

UrlList = folder_config.keys ()

Cl = wx.CheckListBox (panel,-1, (20,20)

(150,300), urlList)

Window.Show (True)

App.MainLoop ()

After the program runs, the interface is as follows

When I want to see a movie, select the movie item and click the Open button, and the program will open the corresponding folder for me instead of looking for it from the drive letter.

This program is almost the same as the previous program that opens the browser, and the code for the click event has been slightly modified to make it more concise.

This is the end of the content of "how to write a gadget to open a folder with wxPython". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Files folders programs code movies tools content actual more knowledge configuration practical concise successful learning next no main program event head dilemma Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux NVidia Docker Shulou Technology OPPO Reno