>>> python -c "import sys; print sys.version"
2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
>>> pip --version
pip 1.5.5 from C:\Python27\lib\site-packages (python 2.7)
>>> pip install py2exe
<mumble grumble..>
RuntimeError: This package requires Python 3.3 or later
Run Code Online (Sandbox Code Playgroud)
虽然官方py2exe下载页面说他们正是我需要的:

那么如何在pip上安装py2exe呢?
据我所知.round(),红宝石中的函数向上舍入小数点,其中最后一个有效数字是5?
例如1.5.round(0) # => 2(好的)
但为什么1.025.round(2) # => 1.02,而不是1.03我所期望的?
irb(main):037:0> 1.025.round(2)
=> 1.02
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能解决这个问题?
我有一个QTreeWidget与QTreeWidgetItems.方法QTreeWidgetItem.flags()返回Qt.ItemFlags实例.
该Qt.ItemFlags类型是QFlags一个typedef.它存储ItemFlag值的OR组合.
那么,现在假设我有一个我的QTreeWidgetItems,我需要找出 - 它是否可以检查?换句话说,我需要在Qt.ItemFlags实例中找到出现ItemFlag(对于我的情况,它是Qt.ItemIsUserCheckable).
怎么做?
这是一个简单而整洁的示例,您可以修改(由注释行标记的感兴趣部分):
import sys
from PyQt4 import QtCore, QtGui
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.treeWidget = QtGui.QTreeWidget()
self.treeWidget.setHeaderHidden(True)
self.addItems(self.treeWidget.invisibleRootItem())
self.treeWidget.itemClicked.connect (self.handleClicked)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.treeWidget)
self.setLayout(layout)
def addItems(self, parent):
column = 0
clients_item = QtGui.QTreeWidgetItem(parent, ['Clients'])
clients_item.setData(column, QtCore.Qt.UserRole, 'data Clients')
clients_item.setExpanded(True)
item_1 = QtGui.QTreeWidgetItem(clients_item, ['Item 1'])
item_1.setData(column, QtCore.Qt.UserRole, 'data Item 1')
item_1.setCheckState(column, QtCore.Qt.Unchecked)
item_2 = …Run Code Online (Sandbox Code Playgroud) 我有一个包含很多变量的 python 模块。许多其他模块使用和更改这些变量。我想在它发生时从它自身重新加载这个模块(为了刷新)。
怎么做?
更新:所以.. 这是我,问题作者,问题发布日期后 8 年。我完全不知道为什么我会尝试做那样的事情。
如果您阅读本文,请尝试使用适当的配置管理技术(大部分时间由您的框架提供)。
# ==================================
# foo.py
spam = 100
def set_spam(value):
spam = value
foo = reload(foo) # reload module from itself
# ==================================
# bar.py
import foo
print foo.spam # I expect 100
# assume that value changes here from some another modules (for example, from eggs.py, apple.py and fruit.py)
foo.set_spam(200)
print foo.spam # I expect 200
Run Code Online (Sandbox Code Playgroud) 我添加(通过拖放)a QDockWidget到我在GUI中编辑的GUI ...
现在我想删除它.
首先,我选择了可见物体并按下了Delete键.
物体消失了.
但是,QDockWidget可以看到对象检查器中仍然存在,
当我尝试保存我的时.ui,我收到消息:
The container extension of the widget MainWindow (QMainWindow)
returned a widget not managed by Designer dockWidget (QDockWidget)
when queried for page #2. Container pages should only be added by
specifying them in XML returned by the domXml() method of the custom
widget.
Run Code Online (Sandbox Code Playgroud)
单击Object Inspector中的Widget并点击Delete键不会执行任何操作,
右键单击上下文菜单没有通常的"Remove"选项.
我怎么摆脱它?!:|
眼镜:
Windows 7 32 bit
PyQt4
Run Code Online (Sandbox Code Playgroud) 我有一个包含大量QDockWidgets并且没有中央小部件的应用程序.我想设置一些QDockWidgets初始大小(应用程序启动时的大小),但我不想限制它们的最小/最大大小.
怎么做?例如,我需要将初始大小设置为150x75到其中一个.我尝试了明显的方法(例如与停靠窗口小部件内容相关的QWidget.Resize()),但它根本不起作用.
这是一个简化的情况模型:
from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([''])
mw = QtGui.QMainWindow() # mw = MainWindow
mw.setCentralWidget(None)
mw.showMaximized()
mw.dockWdg1 = QtGui.QDockWidget(mw)
mw.content1 = QtGui.QTreeWidget()
mw.dockWdg1.setWidget(mw.content1)
mw.addDockWidget(QtCore.Qt.DockWidgetArea(2), mw.dockWdg1)
mw.dockWdg1.setWindowTitle("1st dock widget")
mw.dockWdg2 = QtGui.QDockWidget(mw)
mw.content2 = QtGui.QTreeWidget()
mw.dockWdg2.setWidget(mw.content2)
mw.addDockWidget(QtCore.Qt.DockWidgetArea(1), mw.dockWdg2)
mw.dockWdg2.setWindowTitle("2nd dock widget")
mw.dockWdg3 = QtGui.QDockWidget(mw)
mw.content3 = QtGui.QTreeWidget()
mw.dockWdg3.setWidget(mw.content3)
mw.addDockWidget(QtCore.Qt.DockWidgetArea(1), mw.dockWdg3)
mw.dockWdg3.setWindowTitle("3rd dock widget")
mw.show()
app.exec_()
Run Code Online (Sandbox Code Playgroud) 我需要拿出一张不同列表的条形图
import math
import numpy as np
import matplotlib.pyplot as plt
month=["dec-09","jan","feb"]
n=len(month)
kitchen=[57.801,53.887,49.268]
laundry=[53.490,56.568,53.590]
air=[383.909,395.913,411.714]
other=[519.883,483.293,409.956]
ind=np.arange(n)
width=0.35
p1=plt.bar(ind,kitchen,width,color="cyan")
p2=plt.bar(ind,laundry,width,color="red",bottom=kitchen)
p3=plt.bar(ind,air,width,color="green",bottom=kitchen+laundry)
p4=plt.bar(ind,other,width,color="blue",bottom=kitchen+laundry+air)
plt.ylabel("KWH")
plt.title("winter")
plt.xticks(ind+width/2,("dec-09","jan","feb"))
plt.show()
Run Code Online (Sandbox Code Playgroud)
它只是一个简单的代码,我想把它们叠加但我遇到了一个错误,我不知道该怎么办
p3=plt.bar(ind,air,width,color="green",bottom=kitchen+laundry)
File "C:\Python33\lib\site-packages\matplotlib\pyplot.py", line 2515, in bar
ret = ax.bar(left, height, width=width, bottom=bottom, **kwargs)
File "C:\Python33\lib\site-packages\matplotlib\axes.py", line 5007, in bar
nbars)
AssertionError: incompatible sizes: argument 'bottom' must be length 3 or scalar
Run Code Online (Sandbox Code Playgroud) QTreeWidget上的信号itemChecked和itemUncheсked在哪里?
Qt Signals: (quote from PyQt4 QTreeWidget documentation page)
void currentItemChanged (QTreeWidgetItem *,QTreeWidgetItem *)
void itemActivated (QTreeWidgetItem *,int)
void itemChanged (QTreeWidgetItem *,int)
void itemClicked (QTreeWidgetItem *,int)
void itemCollapsed (QTreeWidgetItem *)
void itemDoubleClicked (QTreeWidgetItem *,int)
void itemEntered (QTreeWidgetItem *,int)
void itemExpanded (QTreeWidgetItem *)
void itemPressed (QTreeWidgetItem *,int)
void itemSelectionChanged ()
Run Code Online (Sandbox Code Playgroud)
目前我解决了这个问题:
self.treeWidget.itemClicked.connect (self.handle)
def handle (item, column):
print 'emitted!', item.text(column)
if item.checkState(column) == QtCore.Qt.Checked:
# there are a lot of my functions inside which work with item data
self.handleChecked(item, column) …Run Code Online (Sandbox Code Playgroud) 如果我有一本字典,如下:
{
'key1':
{
'foo': 1233,
'bar': 1234,
'baz': 122
},
'key2':
{
'foo': 113,
'bar': 333
}
}
Run Code Online (Sandbox Code Playgroud)
如何返回具有以下结果的新字典
{
'key1':
{
'foo': 1233,
'bar': 1234
},
'key2':
{
'foo': 113,
'bar': 333
}
}
Run Code Online (Sandbox Code Playgroud)
我想要'key1'和'key2'的子词典(这是正确的术语?)具有相同的键
Matplotlib完美地在这个应用程序中工作..但由于某种原因没有在构建中工作.为什么?
我很乐意接受任何可以帮助我的建议.
.exe.log:
Traceback (most recent call last):
File "main.py", line 3, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "matplotlib\__init__.pyc", line 103, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "distutils\__init__.pyc", line 25, in <module>
ImportError: cannot import name dist
Run Code Online (Sandbox Code Playgroud)
main.py是我正在构建的脚本.它的第3行:
import matplotlib
Run Code Online (Sandbox Code Playgroud)
build.py:
# encoding: utf-8
import os
import sys
import errno
sys.path.append(os.path.abspath("."))
from distutils.core import setup
import shutil
import py2exe
import matplotlib as mpl
mpl.use('Agg')
distDir = 'dist'
shutil.rmtree('build', ignore_errors=True)
shutil.rmtree(distDir, ignore_errors=True) …Run Code Online (Sandbox Code Playgroud) python ×6
qt ×4
pyqt ×3
pyqt4 ×3
matplotlib ×2
py2exe ×2
qdockwidget ×2
decimal ×1
designer ×1
dictionary ×1
distutils ×1
importerror ×1
pip ×1
pypi ×1
python-2.7 ×1
qtreewidget ×1
rounding ×1
ruby ×1