为了在kivy中指定任何颜色值,我们需要指定从0到1的值,即颜色默认为[1,1,1,1],并且可以包含0到1之间的值,但是rgba代码可以用于其他语言总是指定从0到255我通常从任何网站链接引用它们,如 http://www.rapidtables.com/web/color/RGB_Color.htm
这有助于甚至在各种python工具包示例中pyQt库然而在kivy中它的不同.
有谁知道为什么它指定从0到1,以及是否有任何方法将各种其他语言使用的值编码为kivy颜色代码.例如,如果我想将rgb(192,192,192)更改为kivy颜色代码该怎么办?
我了解到在Qt中我们确实有一些方法来制作QpushButton:
我期待在Kivy中使Buttons行为类似.可能吗 ?我了解到我们可以将背景图像更改为具有圆角形状的图像 更改Kivy中按钮的背景颜色
但这并不令人满意,因为按钮看起来仍然很正常.没有阴影效果.即使我们点击按钮外的角落,如果单击按钮,也会对其进行处理.
我已经阅读了Kivy Button以及Label的文档,并尝试更改按钮的行为和外观.有人可以建议如何使按钮看起来更好我们可以尝试:
下面是我刚刚为了探索Kivy中的按钮而创建的代码:
__author__ = 'pbatra'
#Good info about background
#https://stackoverflow.com/questions/20181250/changing-the-background-color-of-a-button- in-kivy/20181407#20181407
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.image import Image
from kivy.graphics import Color
gui = '''
<MenuScreen>:
canvas.before:
BorderImage:
# BorderImage behaves like the CSS BorderImage
border: 10, 10, 10, 10
texture: self.background_image.texture
pos: self.pos
size: self.size
GridLayout:
size_hint: .1, .1
pos_hint: {'center_x': .5, …Run Code Online (Sandbox Code Playgroud) 嗨,我已经看到在这个问题上已经有很多问题,但是他们似乎都没有回答我的问题.
根据下面的链接我甚至尝试了winpexpect,因为我正在使用Windows,但它似乎正在为我工作. 从ffmpeg获取实时输出以在进度条中使用(PyQt4,stdout)
我正在使用subprocess.Popen运行子程序,并希望在pyQt Widget中看到实时结果.目前它在pyQt小部件中显示结果,但仅在子命令完成执行后才显示.我需要知道当我们可以将子进程的输出实时输入窗口时是否有办法.请参阅下面的代码,我尝试了所有这些.
import sys
import os
from PyQt4 import QtGui,QtCore
from threading import Thread
import subprocess
#from winpexpect import winspawn
class EmittingStream(QtCore.QObject):
textWritten = QtCore.pyqtSignal(str)
def write(self, text):
self.textWritten.emit(str(text))
class gui(QtGui.QMainWindow):
def __init__(self):
# ...
super(gui, self).__init__()
# Install the custom output stream
sys.stdout = EmittingStream(textWritten=self.normalOutputWritten)
self.initUI()
def normalOutputWritten(self, text):
cursor = self.textEdit.textCursor()
cursor.movePosition(QtGui.QTextCursor.End)
cursor.insertText(text)
self.textEdit.ensureCursorVisible()
def callProgram(self):
command="ping 127.0.0.1"
#winspawn(command)
py=subprocess.Popen(command.split(),stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
result,_=py.communicate()
for line in result:
print line
print result
def initUI(self):
self.setGeometry(100,100,300,300)
self.show()
self.textEdit=QtGui.QTextEdit(self)
self.textEdit.show() …Run Code Online (Sandbox Code Playgroud) 我刚刚在 kivy 中创建应用程序后创建了一个 apk,但是在我看来,创建的 apk 的大小在 android 上确实很大,并且在运行应用程序后,大小变得越来越大。请参阅下面的示例:
导入 kivy kivy.require('1.0.6')
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
class MyApp(App):
def build(self):
return Button(text='Hello world')
if __name__ == '__main__':
MyApp().run()
Run Code Online (Sandbox Code Playgroud)
包含上述代码的文件大小:1 kb
使用 python for android 项目创建其 apk 及其大小(6.7 MB): 3.1 ./distribute.sh -m "kivy" 3.2 ./build.py --dir /home/kivy/HelloWorld/ --package org .ex.helloworld --name "HelloWorld" --icon /home/kivy/Work/HelloWorldDistribute/a.png --version 1.3 --orientation Portrait debug installd
kivy@kivy-VirtualBox:~/android/python-for-android/dist/first/bin$ du -h HelloWorld-1.3-debug.apk 6.7M HelloWorld-1.3-debug.apk
使用以下命令在 Android …
我正在尝试在小部件上添加一个按钮并将该按钮绑定到一个函数。与此同时,我正在on_touch_down举办一个活动。
但是,当我按下按钮时,它不会调用该功能;相反,它调用on_touch_down事件。
我怎样才能解决这个问题?
import kivy
kivy.require('1.0.8')
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
class a(Widget):
def on_touch_down(self, touch):
print("touch x is ", touch.x)
print("touch y is ", touch.y)
def update(self,dt):
print("updated")
class mainApp(App):
def build(self):
print("Hi, I am build function")
parent = a()
self.Startbtn = Button(text='Start')
parent.add_widget(self.Startbtn)
self.Startbtn.bind(on_release=self.Loop1)
#Clock.schedule_interval(parent.update, 10.0/1000 )
return parent
def Loop1(self,dt):
print("Hi, this is Loop function")
self.v=1
if __name__ == '__main__':
mainApp().run()
Run Code Online (Sandbox Code Playgroud) 在看了许多使用django渲染图形的选项之后,我认为graphos可能是最好的选择,但是当尝试使用那里运行它非常基本的例子我得到模板的错误不存在异常类型:TemplateDoesNotExist异常值:graphos/flot.html
我从他们的文档中使用了非常基本的代码https://agiliq.com/docs/django-graphos/flot.html:
def index(request):
queryset = Pockets.objects.all()
print "query set is ",queryset
data_source = ModelDataSource(queryset,
fields=['pocket_name', 'sum_pocket'])
chart = flot.LineChart(data_source)
print "chart is ",chart
context_dict.update({'chart': chart})
return render_to_response('a/index.html', context_dict, context)
Run Code Online (Sandbox Code Playgroud)
在我的index.html我正在使用
<div>
<!--for graph stuff-->
{{ chart.as_html }}
</div>
Run Code Online (Sandbox Code Playgroud)
但仍然得到错误TemplateDoesNotExist在/ a /异常类型:TemplateDoesNotExist异常值:graphos/flot.html
无法弄清楚可能是什么问题,文件没有说什么是遗漏.有人可以帮忙吗?
我在ui中使用pyQt Designer创建了一个代码并将其更改为py代码。
现在我想向我的这个添加一些 Keypress 事件,即如果我点击带有数字 3 的键盘键,我的标签上应该有文本 3 或者它只是打印“嗨”
我已经通过互联网检查了很多论坛,发现最好重新实现 keyPressEvent 以使用键盘事件。我尝试过,但是不知何故我无法使其在 pyQT 设计器生成的代码中工作。
下面是 pyQT 设计器生成的代码。我也将 keyPressEvent 重新实现的代码放入其中,但是它不起作用:
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
MainWindow.setFocus()
def keyPressEvent(self, qKeyEvent):
print "hi"
print(qKeyEvent.key())
if qKeyEvent.key() == QtCore.Qt.Key_Return:
print('Enter pressed')
else:
super(Ui_MainWindow).keyPressEvent(qKeyEvent)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.horizontalLayoutWidget = QtGui.QWidget(self.centralwidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(40, 10, 721, 80))
self.horizontalLayoutWidget.setObjectName(_fromUtf8("horizontalLayoutWidget"))
self.horizontalLayout = QtGui.QHBoxLayout(self.horizontalLayoutWidget) …Run Code Online (Sandbox Code Playgroud)