很多时候,我会在wxPython应用程序中对静态文本使用相同的字体方案.目前我正在SetFont()调用每个静态文本对象,但这似乎是很多不必要的工作.但是,wxPython演示和wxPython In Action书中没有讨论这个问题.
有没有办法轻松地将相同的SetFont()方法应用于所有这些文本对象,而不是每次都进行单独的调用?
我想做一个没有边框的wx.TextCtrl使用wxpython:P我该怎么做?
我的问题是,我们是否可以为某个项目分配/绑定某个值并隐藏该值(或者如果我们可以用另一种方式做同样的事情).
示例:假设ListCtrl上的列是"Name"和"Description":
self.lc = wx.ListCtrl(self, -1, style=wx.LC_REPORT)
self.lc.InsertColumn(0, 'Name')
self.lc.InsertColumn(1, 'Description')
Run Code Online (Sandbox Code Playgroud)
当我添加一个项目时,我希望它们显示Name参数和描述:
num_items = self.lc.GetItemCount()
self.lc.InsertStringItem(num_items, "Randomname")
self.lc.SetStringItem(num_items, 1, "Some description here")
Run Code Online (Sandbox Code Playgroud)
现在我想要做的是基本上为未显示的项目分配一些内容,以便稍后我可以在应用程序上访问.
所以我想添加一些未在应用程序上显示但在项目值上的内容,如:
hiddendescription = "Somerandomthing"
Run Code Online (Sandbox Code Playgroud)
还是没有看不到?好吧,我想添加一个按钮来添加一个项目与其他一些TextCtrls来设置参数,TextCtrls参数是:
"名称"
"描述"
"Hiddendescription"
然后,用户填写这些文本,然后单击按钮创建项目,我基本上只想显示名称和描述并隐藏"HiddenDescription"但是这样做我以后可以使用它.
很抱歉在这篇文章中解释了超过1次,但我想确保你理解我假装做的事情.
我有一个Python应用程序,我决定执行.exe来执行它.
这是我用来执行.exe的代码:
# -*- coding: cp1252 -*-
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
windows = [{'script': "SoundLog.py"}],
zipfile = None,
packages=[r"C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Auxiliar", r"C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Plugins"],
)
Run Code Online (Sandbox Code Playgroud)
但是当我使用.exe运行我的应用程序时,图形是完全不同的.
在下面的图像中,您可以看到运行思想python的应用程序在左侧,并且运行时认为右侧是.exe.

如何使.exe与运行思想python的那个一样好?
如果这是一个noob问题,我道歉,但我似乎无法想出这个问题.
我已经定义了一个定义音乐曲目的对象(注意:最初只有ATTRIBUTE和self.ATTRIBUTE.我编辑了这些值以帮助消除混淆.它们对问题没有影响)
class Track(object):
def __init__(self, title, artist, album, source, dest):
"""
Model of the Track Object
Contains the followign attributes:
'Title', 'Artist', 'Album', 'Source', 'Dest'
"""
self.atrTitle = title
self.atrArtist = artist
self.atrAlbum = album
self.atrSource = source
self.atrDest = dest
Run Code Online (Sandbox Code Playgroud)
我使用ObjectListView创建特定目录中的轨道列表
....other code....
self.aTrack = [Track(sTitle,sArtist,sAlbum,sSource, sDestDir)]
self.TrackOlv.AddObjects(self.aTrack)
....other code....
Run Code Online (Sandbox Code Playgroud)
现在我想迭代列表并打印出每个项目的单个值
list = self.TrackOlv.GetObjects()
for item in list:
print item.atrTitle
Run Code Online (Sandbox Code Playgroud)
这失败了,错误
AttributeError: type object 'Track' has no attribute 'atrTitle'
Run Code Online (Sandbox Code Playgroud)
让我感到困惑的是,如果我在对象列表视图显示中突出显示单个项目并使用以下代码,它将正确打印突出显示项目的单个值
list = self.TrackOlv.GetSelectedObject()
print list.atrTitle
Run Code Online (Sandbox Code Playgroud)
编辑:每个请求的完整来源.要查看错误,请浏览到源dir w/.mp3文件,然后单击打印按钮.
#Boa:Frame:Frame1 …Run Code Online (Sandbox Code Playgroud) 是否可以创建具有固定大小的框架,因此用户无法更改框架的大小?
wx.Frame.__init__(self, None, -1, 'Hello',wx.DefaultPosition,(400, 300))
Run Code Online (Sandbox Code Playgroud)
我正在使用 python 2.7
谢谢
要以全屏模式显示wxPython窗口,请使用:
ShowFullScreen(True)
Run Code Online (Sandbox Code Playgroud)
你如何走出全屏?我试过这种明显的方式:
ShowFullScreen(True)
sleep(5)
ShowFullScreen(False)
Run Code Online (Sandbox Code Playgroud)
但这不起作用.当我运行脚本时,没有任何内容出现.5秒钟后,屏幕左上角出现一个大约200x250的窗口,内部没有任何内容.它似乎也没有任何边界.
如果我改成这个
showFullScreen(True)
Run Code Online (Sandbox Code Playgroud)
然后我陷入了一个全屏窗口,我必须使用Alt + F2 - > xkill离开.
在Ubuntu 11.04下Unity中没有托盘.
如何在Unity中的某个位置显示图标?wx.TaskBarIcon不会出现在任何地方.谢谢
我已经阅读了很多与此相关的问题并且学到了很多,但我仍然无法解决我的问题.我正在构建一个运行c ++可执行文件的wxPython应用程序,并实时显示该可执行文件中的stdout.我试图让这项工作遇到几个奇怪的结果.这是我目前的设置/问题:
//test.cc (compiled as test.out with gcc 4.5.2)
#include <stdio.h>
int main()
{
FILE* fh = fopen("output.txt", "w");
for (int i = 0; i < 10000; i++)
{
printf("Outputting: %d\n", i);
fprintf(fh, "Outputting: %d\n", i);
}
fclose(fh);
return 0;
}
#wxPythonScript.py (running on 2.7 interpreter)
def run(self):
self.externalBinary = subprocess.Popen(['./test.out'], shell=False, stdout=subprocess.PIPE)
while not self.wantAbort:
line = self.externalBinary.stdout.readline()
wx.PostEvent(self.notifyWindow, Result_Event(line, Result_Event.EVT_STDOUT_ID))
print('Subprocess still running')
print('Subprocess aborted smoothly')
Run Code Online (Sandbox Code Playgroud)
如果我运行上面的代码,子进程需要很长时间才能完成,即使它只需要写出数据并退出.但是,如果我运行以下内容,它会很快完成:
#wxPythonScript.py (running on 2.7 interpreter)
def run(self):
outFile = open('output.txt', 'r+') …Run Code Online (Sandbox Code Playgroud) 我已经看到了关于这个话题的另一个问题,但是我无法得到适合我的信息,所以我想我会详细说明 - 我怀疑我只是短视.
我正在尝试从测试框架中运行我的GUI,这涉及在测试脚本中手动调用事件(在这种情况下是按下按钮).到目前为止,除了其他不相关的guff,我还有:
# In GUI class:
self.button_1 = wx.Button(self, id=wx.ID_ANY, label="Button 1")
self.button_1.Bind(wx.EVT_BUTTON, self.button_1)
# In GUI Test class:
event = wx.PyCommandEvent(X, Y)
wx.PostEvent(get_gui_instance(), event)
Run Code Online (Sandbox Code Playgroud)
我的问题是我不知道应该是什么X,Y应该是什么(假设其余的都没问题).任何帮助是极大的赞赏.