In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to write a gadget with wxPython". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to write a gadget with wxPython.
Used to open frequently used websites, after the program starts, the interface looks like this
Program code configuration file
Create a new file called config.py with the following contents
# coding=utf-8
Urlconfig = {
U 'Baidu': 'http://www.baidu.com',
Ubiquitous CSDN http://www.csdn.net',
U 'rookie world': 'http://www.zhangdongshengtech.com'
}
Main program
Create a new file named browser.py in the same directory with the following contents
# coding=utf-8
Import wx
Import os
From config import urlconfig
Def clickbtn (event):
Namelist = cl.GetCheckedStrings ()
# Open the URL
For name in namelist:
Command = "explorer {url}" .format (
Url=urlconfig [name])
Os.system (command)
# uncheck
Checkindex = cl.GetChecked ()
For index in checkindex:
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 = urlconfig.keys ()
Cl = wx.CheckListBox (panel
-1, (20,20), (150,300), urlList)
Window.Show (True)
App.MainLoop ()
Introduction of program interpretation control
Frame is a window control
Button is a button control
CheckListBox is a set of selection boxes, which are the controls you see on the left side of the image above. You can choose either one or multiple selections.
Control relationship
When each control is created, it must indicate who its parent control is, so that the controls are stacked layer by layer.
Event binding
Panel.Bind (wx.EVT_BUTTON, clickbtn, b) binds an event to the button control and executes the clickbtn function when the button is clicked
Clickbtn function
In the clickbtn function, the GetCheckedStrings method returns the string of the selected option, which is what can be seen on the interface. The option allows multiple selections, and the return value of the method is a tuple.
The GetChecked method returns the index number of the selected option, and the return value is also a tuple,GetCheckedStrings method and the GetChecked method actually return the information of the selected option, one is the index number, the other is the name string, it is reasonable to provide a function to return the two information at the same time, but I have not found the method yet.
The Check method sets the selected state of the option. The first parameter is the index number of the option, and the second parameter is the selected state. After each URL is opened, the previous selected state should be unchecked. Therefore, I set all the selected options to False.
At this point, I believe you have a deeper understanding of "how to write a gadget with wxPython". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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: 0
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.