kivy python 读取oracle数据库_Kivy和Python线程-如何在它们之间获取数据
我在python(threading)和kivy上遇到一些问题:
这是一些代码:
import kivy
import threading
import time
from kivy.app import App
from kivy.uix.button import Button
class Thread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.counter = 0
def run(self):
while True:
print "Thread is running " str(self.counter)
app.button.text = self.set_button(self.counter)
app.button.text = str(self.counter)
time.sleep(0.5)
def count(self):
self.counter = 1
app.button.text = str(self.counter)
def set_button(self, value):
app.button.text = str(value)
class MyApp(App):
def __init__ (self, thread_object):
App.__init__(self)
self.thread_object = thread_object
def callback(self,instance):
print('The button is being pressed' % instance.text)
self.thread_object.count()
def build(self):
self.button = Button(text='Hello World')
self.button.bind(on_press=self.callback)
return self.button
thread = Thread()
thread.start()
app = MyApp(thread)
app.run()
现在-此代码只需一个按钮即可打开kivy应用程序.任务是:按下按钮,一些数据应显示在线程代码中(通过“ count”方法执行).
问题是相反的-线程代码应更改按钮的文本.我尝试了两种方法:
>直接编写:app.button.text = str(self.counter)
>通过“ set_button”方法编写:app.button.text = self.set_button(self.counter)
它们都显示错误“属性错误:’MyApp’对象没有属性’按钮’”.
有没有任何方法可以直接交换数据而无需请求,即使不使用“ thread_object”在此处进行指针操作
def __init__ (self, thread_object):
谢谢你的帮助.
解决方法:
这可能会解决您的所有问题.那就是我喜欢在处理线程和奇异语言时进行编码的方式.
这是thread.py文件
import threading
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import NumericProperty
class Thread(BoxLayout):
counter = NumericProperty(0)
def Counter_function(self):
self.counter = 1
self.ids.lbl.text = "{}".format(self.counter)
def First_thread(self):
threading.Thread(target = self.Counter_function).start()
self.counter = 1
self.ids.lbl.text = "{}".format(self.counter)
class MyApp(App):
def build(self):
self.load_kv('thread.kv')
return Thread()
if __name__ == "__main__":
app = MyApp()
app.run()
这是thread.kv文件
:
Button:
text: "use thread"
on_release: root.First_thread()
Button:
text: "Hit me"
on_release: root.Counter_function()
Label:
id: lbl
text: "Numbers"
现在,您在评论中说,您在动态加载GUI方面遇到困难.所以,这是一个例子.
Builder.load_string('''
[SideBar@BoxLayout]:
content: content
orientation: 'vertical'
size_hint: .2,1
BoxLayout:
orientation: 'vertical'
# just add a id that can be accessed later on
id: content
:
Button:
center_x: root.center_x
text: 'press to add_widgets'
size_hint: .2, .2
on_press:
sb.content.clear_widgets()
root.load_content(sb.content)
SideBar:
id: sb
''')
class Root(BoxLayout):
def load_content(self, content):
for but in range(20):
content.add_widget(Button(text=str(but)))
class MyApp(App):
def build(self):
return Root()
来源:https://www.icode9.com/content-1-567301.html
kivy python 读取oracle数据库_Kivy和Python线程-如何在它们之间获取数据相关推荐
- python读取oracle数据库中文乱码_PL/SQL连接Oracle数据库,中文乱码,显示问号
PL/SQL连接oracle数据库 1.简单介绍 在不安装oracle数据库的情况下使用pl/sql连接远程oracle数据库. 2.详细步骤: a) 安装PL/SQL.依据自己的操作系统安 ...
- python读取oracle数据库性能_用python对oracle进行简单性能测试
一.概述 dba在工作中避不开的两个问题,sql使用绑定变量到底会有多少的性能提升?数据库的审计功能如果打开对数据库的性能会产生多大的影响?最近恰好都碰到了,索性做个实验. sql使用绑定变量对性能的 ...
- python读取oracle数据库性能_python 连接oracle数据库,报错解决,pandas读取。
背景:工作需要,windows环境下要用python连接oracle,用pandas处理数据. 目标:连接oracle,并读取为DataFrame格式. 连接oracle是个大坑,尝试了很久终于整好了 ...
- python读取oracle数据库数据库_Python读写Oracle数据库
最近项目中需要用到Python调用Oracle实现读写操作,踩过很多坑,历尽艰辛终于实现了.性能怎样先不说,有方法后面再调优嘛.现在把代码和注意点记录一下. 1. 所需Python工具库 cx_Ora ...
- python操作Oracle数据库
1. 准备工作 ① 首先,你必须安装好Oracle数据库.Oracle数据库的安装并不是那么容易,大家可以去找一个安装教程,慢慢研究. ② 其次,你既然用Python操作Oracle,你必须要安装Py ...
- Python+Pandas 读取Oracle数据库
Python+Pandas 读取Oracle数据库 import pandas as pd from sqlalchemy import create_engine import cx_Oracle ...
- python访问数据库如何解决高并发_使用 Python 和 Oracle 数据库实现高并发性
随着趋势发展的核心转向更多而不是更快发展,最大限度地提高并发性的重要性日益凸显.并发性使得编程模式发生了新的转变,可以编写异步代码,从而将多个任务分散到一组线程或进程中并行工作.如果您不是编程新手并且 ...
- python连接本机oracle数据库吗,用Python连接Oracle数据库容易吗?
ello,大家好!本次介绍的内容是如何使用Python连接Oracle数据库!看起来很简单,但实际上就是这么简单.学习本节内容后,相信老铁们能用Python撸起你们那庞大的Oracle数据库了.Wel ...
- Python 技术篇-连接oracle数据库并执行sql语句实例演示,python连接oracle数据库oci详细配置方法
Python 连接 Oracle 数据库 第一章:连接 oracle 数据与环境配置 ① 连接 oracle 数据库效果演示 ② oci 下载 ③ oci 配置 ④ 环境变量配置 ⑤ 检测是否有 or ...
最新文章
- WebService大讲堂之Axis2(5):会话(Session)管理
- Keepalived实现LVS的高可用全解析
- VS2019中在源文件中如何使用自己写的头文件(保姆级教程)
- dll文件用什么语言编写_零基础学习markdown标记语言语法,十分简单便捷编写markdown文件...
- 一个***与一个电脑白痴的经典对白
- linux端口 fcs校验,我如何接收错误的以太网帧并禁用CRC / FCS计算?
- java se 定时任务_Java实现定时任务的三种方法
- java8 di_java8 多个list对象用lambda求差集操作
- Android WebView 问题总集
- 【翻译】在Ext JS 6通用应用程序中使用既共享又特定于视图的代码
- concurrenthashmap是什么锁_JDK1.8 util-concurrent-ConcurrentHashMap源码分析
- dubbo 自定义路由_高性能可扩展分布式RPC框架Dubbo内核原理揭秘
- 一个软件,internal version 和external version, 安装有问题
- bootstrap table 服务器端分页--ashx+ajax
- 模拟银行叫号系统(c代码)
- jenkins插件镜像源
- 实例079RTF文件的保存
- [渝粤教育] 九江学院 看影视学社交礼仪 参考 资料
- Golang 字符串拼接
- scrollViewDidEndDragging和scrollViewDidEndDecelerating有什么区别呢
热门文章
- JGG :微生物所王军-综述固有免疫细胞在胃肠道疾病中研究进展
- Nature子刊:利用转细菌基因植物修复土壤有毒污染物!
- GraPhlAn绘制的超高颜值物种树Cladogram
- 2019微生物组—宏基因组分析技术研讨会第六期
- 植物MWAS研究—小米产量与微生物组关联分析
- R语言ggplot2可视化:使用热力图可视化dataframe数据
- R语言使用magick包的image_border函数和image_background函数自定义图像的边界和背景(Change image border and background)
- seaborn使用Catplot函数可视化水平小提琴图(Make Horizontal Violin Plot with Catplot in Seaborn)
- R语言使用ggplot2包使用geom_boxplot函数绘制基础分组箱图(分组箱体框颜色配置)实战
- 为什么决策树相关的算法不需要标准化?那么那些模型需要标准化那?