我注意到当你在Kivy中使用网格布局制作按钮时,它们是在(0,0)处创建的,并且根据前一个按钮的长度和宽度移动多个空格.但是,我想在屏幕底部中间有一个3x4网格.
到目前为止我有这个:
import kivy
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
from kivy.uix.button import Button
class CalcApp(App):
def build(self):
layout = GridLayout(cols=3, row_force_default=True, row_default_height=50)
layout.add_widget(Button(text='1', size_hint_x=None, width=100))
layout.add_widget(Button(text='2', size_hint_x=None, width=100))
layout.add_widget(Button(text='3', size_hint_x=None, width=100))
layout.add_widget(Button(text='4', size_hint_x=None, width=100))
layout.add_widget(Button(text='5', size_hint_x=None, width=100))
layout.add_widget(Button(text='2', size_hint_x=None, width=100))
layout.add_widget(Button(text='6', size_hint_x=None, width=100))
layout.add_widget(Button(text='7', size_hint_x=None, width=100))
layout.add_widget(Button(text='8', size_hint_x=None, width=100))
layout.add_widget(Button(text='9', size_hint_x=None, width=100))
layout.add_widget(Button(text='0', size_hint_x=None, width=100))
layout.add_widget(Button(text='Enter', size_hint_x=None, width=100))
return layout
CalcApp().run()
Run Code Online (Sandbox Code Playgroud)
那么,我该如何改变立场?
我刚刚开始使用kivy开发用于测试目的并构建第一个.apk,因此我想到了一个问题.
main.py包含源代码,如果我想分发我的apk,可能我不想"可读"...所以当我为Google Play创建.apk时,有没有办法编码或隐藏我的主要代码存储或作为一个普通的Linux应用程序?
多谢你们!
class MyPaintWidget(Widget):
def on_touch_down(self, touch):
userdata = touch.ud
with self.canvas:
Color(1, 1, 0)
d = 30.
Ellipse(pos=(touch.x - d/2, touch.y - d/2), size=(d, d))
userdata['line'] = Line(points=(touch.x, touch.y))
Run Code Online (Sandbox Code Playgroud)
显然Color,d并且Ellipse在命名空间内self.canvas,但Python如何知道userdata不在同一个命名空间内?
如何创建简单的 Kivy 应用程序?
如果用户像在 android 手机上一样使用键盘在“名称”字段中输入文本,则显示该名称
我需要这个来学习
如果我想on_press在任何程序中向弹出窗口添加事件,我可以直接在python中或使用kv语言.
例如,如果我使用Python
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.button import Button
class SomePopup(Popup):
pass
class SomeBox(Box):
popup = SomePopup()
popup.title = 'anything'
popup.content = Button(text='anytext', on_press=popup.dismiss)
Run Code Online (Sandbox Code Playgroud)
在KV语言中,假设我制作相同的弹出窗口,它将是.
<SomePopup>
title: 'anything'
content: popupContent
Button:
id: popupContent
text: 'anytext'
on_press: root.dismiss()
Run Code Online (Sandbox Code Playgroud)
所以,在python中,我必须使用on_press=popup.dismiss和kv语言on_press: root_dismiss()
我不明白为什么在kivy语言中我应该使用括号而不是python.请问你能帮帮我吗?
我正在使用 Kivy 构建一个 python 桌面应用程序,并想了解如何创建一个类似于 EVE Online 的无边框窗口:EVE Online launch screen。
这就是我现在所处的位置,以及我下一步想要实现的目标:我想要实现的目标
我花了好几个小时在谷歌上搜索一个解决方案,但最接近的是这些链接:如何隐藏主窗口标题栏并在 kivy 框架中放置透明背景?,还有这个:wxPython 中的无边框窗口
这是当前代码(Python 2.7,Kivy 1.9):
from kivy.app import App
from kivy.uix.button import Button
from kivy.config import Config
Config.set('graphics', 'width', '480')
Config.set('graphics', 'height', '320')
Config.set('graphics', 'borderless', '1')
class MyApp(App):
def build(self):
button = Button(text="Exit", size_hint=(None, None))
button.bind(on_press=exit)
return button
if __name__ == '__main__':
MyApp().run()
Run Code Online (Sandbox Code Playgroud)
我想看看这是否可以在 Kivy 中完成。你能提出一些解决这个问题的方法吗?谢谢!
我有一个像这样的方形按钮:
from kivy.app import App
from kivy.uix.button import Button
class MyTestApplication(App):
def build(self):
b = Button(size_hint=(None, None), height=200, width=200,
background_normal='my_icon.png')
return b
MyTestApplication().run()
Run Code Online (Sandbox Code Playgroud)
当我使用与存储图像不同的按钮大小时,我设置为按钮背景的图像会失真。
当我使用height=100and width=100(这些是 的实际尺寸
my_icon.png)时,它看起来像预期的那样。
和
问题:
是什么导致了这种失真,我该如何解决?
我正在尝试按照YouTube视频上的教程进行操作.
但是from kivy import App给出了ImportError: cannot import name App.我怎样才能解决这个问题?
我已经安装了kivy 1.8.0和cython 0.20
pip freeze 回报
adium-theme-ubuntu==0.3.4
Cython==0.20
Kivy==1.8.0
Kivy-Garden==0.1.1
numpy==1.11.0
pygame===1.9.1release
requests==2.11.0
unity-lens-photos==1.0
virtualenv==15.0.3
Run Code Online (Sandbox Code Playgroud) 我试过在互联网上寻找解决我的问题。但它根本没有结果。所以。请查看此代码示例:
class RootWidget(FloatLayout):
def __init__(self, **kwargs):
super(RootWidget, self).__init__(**kwargs)
btn = Button(text='Hello world')
btn.size_hint = (1, .3)
btn.pos_hint = {'top':1}
title = Label(text=('[color=ff3333]Hello world[/color]'),
font_size=str(12) + 'sp', markup=True)
self.add_widget(title)
self.add_widget(btn)
title.texture_update()
title.text_size = (Window.width, None)
title.height = title.texture_size[1]
with title.canvas:
Color(1., 1., 0)
Rectangle(size=title.size, pos=title.pos)
print(title.size)
print(title.pos)
print(title.texture_size)
Run Code Online (Sandbox Code Playgroud)
现在看看图像:

谁能告诉我为什么打印(title.pos)说(0,0),画布在(0,0)处绘制矩形但文本出现在另一个位置?
我已经被这个淹没了......
谢谢你。
我正在 Kivy 中创建一个 Python 程序,它允许用户登录或创建一个新帐户。我在 MySQL 中有一个 Python 程序引用的用户名和密码表(通过 PyMySQL)。当新用户输入一个已经存在的用户名时,Python 会遍历 MySQL 表中的每个用户名,如果用户名已经存在,Python 会要求用户输入一个新密码。问题是,当用户尝试输入新用户名并且 Python 再次运行代码时,我收到“TypeError: 'unicode' object is not callable”。我很困惑,因为如果用户第一次输入一个不存在的用户名,我不会出错。当他们再次尝试输入用户名时,我收到错误消息。
这是我的 .py 主文件代码块,它给我带来了问题:
#Select all usernames from the database with the execute method
cur.execute("""SELECT username FROM patient_login""")
#Use the fetchall() method to get a list dictionary of all usernames
self.usernames_from_db = cur.fetchall()
#For each of the names in the list/dict of usernames
for names in self.usernames_from_db:
#If the names username is equal to the username the user created
if …Run Code Online (Sandbox Code Playgroud)