我想在for循环中使用附加到它的整数创建字符串.像这样:
for i in range(1,11):
string="string"+i
Run Code Online (Sandbox Code Playgroud)
但它返回一个错误:
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Run Code Online (Sandbox Code Playgroud)
连接String和Integer的最佳方法是什么?
from Tkinter import *
root = Tk()
cv = Canvas(root)
cv.create_rectangle(10,10,50,50)
cv.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
我想将画布内容转换为位图或其他图像,然后执行其他操作,例如旋转或缩放图像,或更改其坐标.
位图可以提高效率,以显示我是否不再绘图.
我该怎么办?
基于这个答案/sf/answers/53845501/,我在抓取区域中创建了以下代码打印值:
import sys
from PyQt4.QtGui import QPixmap, QApplication
app = QApplication(sys.argv)
# img is QImage type
img = QPixmap.grabWindow(
QApplication.desktop().winId(),
x=00,
y=100,
height=20,
width=20,
).toImage()
for x in range(0,20):
for y in range(0,20):
print( "({},{}) = {}".format( x,y,(img.pixel(x,y)) ) )
Run Code Online (Sandbox Code Playgroud)
但像素显示如下:
(0,0) = 4285163107
(0,1) = 4285163107
(0,2) = 4285163107
(0,3) = 4285163107
(0,4) = 4285163107
(0,5) = 4285163107
Run Code Online (Sandbox Code Playgroud)
如何获得QImage(从QPixmap)像素的RGB值?(最好是在16,24,32屏幕位深度下工作的解决方案)?
示例输出:
(0,0) = (0,0,0)
...
(10,15) = (127,15,256)
Run Code Online (Sandbox Code Playgroud)
(Linux解决方案,用Python3编写)
有没有人知道类似于Java Robot的Python类?
具体来说,我想在Ubuntu中执行屏幕抓取,并最终跟踪鼠标点击和键盘按下(尽管这是一个稍微不同的问题).
我将从此页面截取屏幕截图:http://books.google.de/books? id = gikDAAAAMBAJ&p = PA1&img = 1&w = 2500或保存其输出的图像.
但我找不到办法.使用wget/curl,我得到一个"不可用的错误",还有其他工具,如webkit2png/wkhtmltoimage/wkhtmltopng.
有没有一个干净的方法来使用python或命令行?
最好的祝福!
A PIL.Image.grab()大约需要0.5秒.这只是为了从屏幕上获取数据到我的应用程序,而我没有任何处理.另一方面,FRAPS可以截取高达30 FPS的屏幕截图.我有什么方法可以从Python程序中做同样的事情吗?如果没有,C程序怎么样?(我可以使用Python程序与它接口,可能...)
来自PIL的ImageGrab本来是理想的.我正在寻找类似的功能,特别是能够定义屏幕截图的边界框.我一直在寻找一个可以在Mac OS X上运行的库,但没有任何运气.我也无法找到任何示例代码(也许是pyobjc?).
我正试图用C和GTK截取整个屏幕的截图.出于速度原因,我不想打电话给外部应用程序.我已经为此找到了Python代码(通过python脚本截取屏幕截图.[Linux]); 我只需要弄清楚如何在C中做到这一点.
出于测试和文档目的,我想创建一个gtk.Window对象的屏幕截图.我正在关注一个基本的pygtk样本.我修改的示例如下所示:
import gtk
def main():
button = gtk.Button("Hello")
scroll_win = gtk.ScrolledWindow()
scroll_win.add(button)
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.add(scroll_win)
win.show_all()
if win.is_drawable() is not True:
raise RuntimeError("Not drawable?")
width, height = win.get_size()
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8,
width, height)
screenshot = pixbuf.get_from_drawable(win, win.get_colormap(),
0, 0, 0, 0, width, height)
screenshot.save('screenshot.png', 'png')
if __name__ == '__main__':
main()
gtk.main()
Run Code Online (Sandbox Code Playgroud)
调用get_from_drawable方法时,我最终会出错.
TypeError: Gdk.Pixbuf.get_from_drawable() argument 1 must be gtk.gdk.Drawable, not gtk.Window
Run Code Online (Sandbox Code Playgroud)
显然,我合并到基本示例中的屏幕截图示例是使用从gtk.gdk.Drawable继承的gtk.gdk.Window.
我的问题:
我有这个需要x屏幕截图的python代码。
#!/usr/bin/python
import gtk.gdk
w = gtk.gdk.get_default_root_window()
sz = w.get_size()
print "The size of the window is %d x %d" % sz
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
if (pb != None):
pb.save("screenshot.png","png")
print "Screenshot saved to screenshot.png."
else:
print "Unable to get the screenshot."
Run Code Online (Sandbox Code Playgroud)
它有效,但是我需要导入from gi.repository import Gdkgtk.gdk。我尝试了以下方法:
#!/usr/bin/python
from gi.repository import Gtk, Gdk, GdkPixbuf
from gi.repository.GdkPixbuf import Pixbuf
w = Gdk.get_default_root_window()
sz = w.get_size()
print "The size of the window is %d x %d" % sz …Run Code Online (Sandbox Code Playgroud) python ×9
screenshot ×5
gtk ×2
image ×2
linux ×2
pygtk ×2
automation ×1
awtrobot ×1
bitmap ×1
c ×1
command-line ×1
gdk ×1
import ×1
integer ×1
macos ×1
optimization ×1
performance ×1
pyqt ×1
pyqt4 ×1
string ×1
tkinter ×1
web ×1