【发布时间】:2021-11-21 07:02:42
【问题描述】:
我是 python 的初学者(也是 kivy)。 4天前我开始学习kivy(也许kivymd)。我学习了它的基础知识。但是我遇到了一些问题,在学习 kivy 之前我学习了tkinter。所以我在 tkinter 中给出了我想用 kivymd 做的例子。
我tkinter:
from tkinter import *
import random
def change_word():
site_list=['Google','Yahoo','Microsoft','APKpure','APKMB','Stackoverflow','Bing']
text=random.choice(site_list)
button_text.config(text=text)
button_text.update()
root=Tk()
root.title('Help Me')
root.geometry('400x400')
button_text=Label(root,text='Click the Button Below to Change This Text',font='arial 15')
button_text.pack(pady=40)
button=Button(root,text='Change It',font='arial 15',command=change_word)
button.pack(pady=10)
root.mainloop()
我可以使用idname.config() 来编辑文本并使用idname.update() 来更新带有def/Function 的Label/Text。
在基维姆德:
from kivymd.app import MDApp
from kivy.lang import Builder
import random
from kivy.core.window import Window
Window.size=(400,600)
please_anwser_this="""
MDScreen:
MDLabel:
id:text-update
text:'Click The Button below to Change this text'
halign:'center'
pos_hint:{'center_x':0.5,'center_y':0.6}
MDFillRoundFlatIconButton:
text:'Change It'
pos_hint:{'center_x':0.5,'center_y':0.5}
icon:'crop-rotate'
on_press:
#What Command Should I type Here to Update 'text-update'/MDLabel's text?
"""
class AnsweredOrNot(MDApp):
def build(self):
builder=Builder.load_string(please_anwser_this)
return builder
def change_word(self): #What Parameters should I give after self?
site_list=['Google','Yahoo','Microsoft','APKpure','APKMB','Stackoverflow','Bing']
text=random.choice(site_list)
AnsweredOrNot().run()
我想在按下按钮时使用函数/def(如 tkinter/任何其他方式)更新 MDLabel.text/text-update.text。谁能帮帮我?
【问题讨论】:
标签: python tkinter kivy kivymd