关于从Popup窗口获取值并在另一个Class中使用的Kivy

时间:2019-11-05 09:32:04

标签: kivy screen popupwindow

嗨,我是新手,刚开始编程。因此,我想做的是,一旦在弹出窗口中输入了有效日期/时间的用户密钥,弹出窗口就会关闭,并转到屏幕并创建按钮。我可以知道如何传递从getDay()获得的值吗,它是dayoutput,popupwindow的timeoutput并在另一个其他类中进行传递?

谢谢〜

class SetDateTime(Popup):

   def getDay(self):

    set_day = (self.ids.dayofmonth).text
    set_month = (self.ids.month).text
    set_year = (self.ids.year).text

    set_hour = (self.ids.houroftime).text
    set_minutes = (self.ids.minuteoftime).text

    wrongtime = self.ids.wronginput_time

    #Calculate Date and Time only when user input a valid number
    if set_day.isdigit() and set_month.isdigit() and 
           set_year.isdigit()andset_hour.isdigit() 
           and set_minutes.isdigit():           
       try:
        set_date = datetime.date(int(set_year), 
                int(set_month),int(set_day))
        set_time = datetime.time(int(set_hour), int(set_minutes))

        if not (set_date >= counttime.todaydate()):
                wrongtime.text = "[color=#FF0000]Date is out of range[/color]"
            if not (set_time >= counttime.todaytime()):
                       wrongtime.text = "[color=#FF0000]Time is out of 
                       range[/color]"

                    dayoutput = counttime.calculatedate(set_date)
                    timeoutput = set_hour + set_minutes
            return dayoutput,timeoutput
       except ValueError:
        wrongtime.text = "[color=#FF0000]Please enter a valid 
                                 datetime.[/color]"

     else:
       wrongtime.text = "[color=#FF0000]Please enter a valid date[/color]"

class VariesTimeScreen(Screen):

    def __init__(self, **kwargs):
        super(VariesTimeScreen, self).__init__(**kwargs)

        a = '_icons_/mcdonald.png'
        b = '_icons_/kfc.png'
        c = '_icons_/subway.png'

        Outlet_Store = [a,b,c]
        layout = GridLayout(rows=1, spacing=100, size_hint_y=None, 
                         pos_hint ={"top":.6,"x":0.2})
        layout.bind(minimum_height=layout.setter('height'))

                #Before the for loop there will be an if statement which is 
                the Day and Time i get from getDay() values. This part i'm 
                unsure how to retrieve the values from the SetDateTime Class

                for image in Outlet_Store: 
                   food_image = ImageButton(size_hint=(None, None),size= 
                                (100,100),source=image)

            layout.add_widget(food_image)
        self.add_widget(layout)

0 个答案:

没有答案