mercredi 16 juin 2021

I want to generate random words as labels. i tried so many thing and it wouldn't work

by clicking correct button I want to generate random words from text document word list as labels. in python kivy. Here are my codes below:

import kivy
import random
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
from kivy.uix.slider import Slider
from kivy.uix.pagelayout import PageLayout
from kivy.properties import ObjectProperty, NumericProperty, StringProperty

class Begin1After(FloatLayout):
    count = 0
    my_text = StringProperty("0")

    def check_off(self):
        self.count += 1
        self.my_text = str(self.count)

    def incorrect_off(self):
        self.count -= 1
        self.my_text = str(self.count)

class MyApp(App):
    pass

myapp = MyApp()
myapp.run()

And here is my kivy code:

<Begin1After>:

    Label:
        text: root.my_text
        pos_hint: {'x': .03, 'y': .35}
        font_size: 20
        bold: True

    Label:
        text: "Team One:"
        bold: True
        pos_hint: {'x': -.05, 'y': .35}
        font_size: 20

    Button:
        size_hint: .06, .08
        pos_hint: {'x': .65, 'y': .1}
        background_color: 0, 0, 0, 0
        on_release: root.check_off()

    Button:
        size_hint: .06, .08
        pos_hint: {'x': .3, 'y': .1}
        background_color: 0, 0, 0, 0
        on_release: root.incorrect_off()



Aucun commentaire:

Enregistrer un commentaire