Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write a gadget to open a folder with wxPython

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 247

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report