live_scoreboard.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:live_scoreboard 作者: ClysmiC 项目源码 文件源码
def update(self):
        self.canvas.delete("updates")

        self.textY = 0
        lastDateLabelDay = None
        firstHour = True

        for hour in self.weather:
            time = hour["time"]
            if time.day != lastDateLabelDay:
                dayString = months[time.month] + " " + str(time.day)

                # New lines
                if lastDateLabelDay is not None:
                    self.textY += self.lineHeight

                self.textY += self.lineHeight

                dayTextOffset = self.font.measure("  ")
                textPosition = (max(0, self.textX - dayTextOffset), self.textY)
                self.canvas.create_text(textPosition, anchor=tk.NW, text=dayString, font=self.underlinedFont, fill=fontColor, tags="updates")

                self.textY += self.lineHeight * 1.2 # just a little extra padding here looks better
                lastDateLabelDay = time.day

            if TWENTY_FOUR_HOUR_CLOCK:
                hourString = " {:02d}:{:02d}".format(time.hour, time.minute) + " - " + "{:>3s}".format(hour["temp"]) + " F "
            else:
                timeHour, suffix = toTwelveHourClock(time)
                hourString = " {:02d}:{:02d} {:s}".format(timeHour, time.minute, suffix) + " - " + "{:>3s}".format(hour["temp"]) + " F "

            hourFontColor = fontColor
            if firstHour:
                hourFontColor = "black"

                # draw a yellowish highlight on the current hour
                highlightColor = '#FFFF99'

                highlightX1 = self.textX
                highlightY1 = self.textY - ((self.lineHeight - self.fontHeight) / 2)
                highlightX2 = highlightX1 + self.font.measure(hourString)
                highlightY2 = highlightY1 + self.lineHeight

                self.canvas.create_rectangle((highlightX1, highlightY1, highlightX2, highlightY2), fill=highlightColor, tags="updates")

            self.canvas.create_text((self.textX, self.textY), anchor=tk.NW, text=hourString, font=self.font, fill=hourFontColor, tags="updates")


            icon = self.weatherIcons[hour["condition"]]
            self.canvas.create_image((self.iconX, self.textY), anchor=tk.NW, image=icon, tags="updates")

            self.textY += self.lineHeight
            firstHour = False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号