Kivy app screenshot 我在同一个项目中有2个.py文件,名为dailyReports.py和weeklyReports.py,它们每个都生成一个不同的Excel工作表,一个每日报告,另一个每周报告。当我点击运行时,它会直接打开excel文件,这就是我想要的。 我试图创建一个简单的用户友好界面,允许用户选择他们想要生成的报告,并运行相应的报告生成器并输出excel文件。这是我第一次处理python和kivy,但到目前为止,我能够使我的两个报告生成器工作,我的kivy GUI的视觉方面正是我想要的。我的问题是当我尝试将下拉菜单中的两个按钮绑定到它们的excel生成器函数时。有人可以帮帮我吗?到目前为止,这是我的.py文件的代码,其中包含我的kivy代码以及当我点击下拉按钮时当前kivy GUI的样子。 我真的很感激!!!!
from kivy.uix.label import Label
from kivy.uix.dropdown import DropDown
from kivy.app import App
from kivy.graphics import Color, Rectangle
from kivy.uix.floatlayout import FloatLayout
from kivy.graphics.context_instructions import Color
from kivy.config import Config
from kivy.uix.image import Image
from kivy.uix.button import Button
dropdown = DropDown()
class Panel(FloatLayout):
def __init__(self, **kw):
super(Panel, self).__init__(**kw)
# Make the background solid white
color = Color(1.0, 1.0, 1.0, 1.0)
self.canvas.add(color)
rect = Rectangle(pos=self.pos, size=self.size)
self.canvas.add(rect)
dropdown = DropDown()
# Add the label
label = Label(text="Report Generator", pos_hint={'x': 0, 'y': 0.20}, size_hint=(None, None))
label.color = [0.0, 0.0, 0.0, 1.0]
label.size_hint = (1, 1)
label.font_size = 26
label.bold = True
self.add_widget(label)
choice = Button(text="Select Summary Report to Generate", pos_hint={'center_x': .5, 'center_y': .58},
size_hint=(0.6, 0.2))
choice.color = [1.0, 1.0, 1.0, 1.0]
choice.size_hint = (0.45, 0.1)
choice.font_size = 18
choice.bold = False
choice.bind(on_release=dropdown.open)
self.add_widget(choice)
btn1 = Button(text='Daily Report', font_size=18, size_hint_y=None, height=60)
btn1.color = [1, 1, 1, 1]
btn1.txt= 'Generating Daily Summary Report...'
btn1.bind(on_release=lambda btn1: dropdown.select(btn1.txt))
dropdown.add_widget(btn1)
btn2 = Button(text='Weekly Report', font_size=18, size_hint_y=None, height=60)
btn2.color = [1, 1, 1, 1]
btn2.txt = 'Generating Weekly Summary Report...'
btn2.bind(on_release=lambda btn2: dropdown.select(btn2.txt))
dropdown.add_widget(btn2)
dropdown.bind(on_select=lambda instance, x: setattr(choice, 'text', x))
class Report(App):
def build(self):[enter image description here][1]
Config.set('graphics', 'width', '450')
Config.set('graphics', 'height', '250')
return Panel(size=(1000,1000))
# Application Code
if __name__ == '__main__':
Report().run()
答案 0 :(得分:0)
您已根据代码段添加以下代码。有关完整的详细信息,请参阅以下示例。
from DailySummaryReport import DailySummary
from WeeklySummaryReport import WeeklySummary
...
btn1.bind(on_release=lambda btn1: dropdown.select(btn1.txt))
btn1.bind(on_release=lambda btn1: DailySummary())
...
btn2.bind(on_release=lambda btn2: dropdown.select(btn2.txt))
btn2.bind(on_release=lambda btn2: WeeklySummary())
from DailySummaryReport import DailySummary
from WeeklySummaryReport import WeeklySummary
from kivy.uix.label import Label
from kivy.uix.dropdown import DropDown
from kivy.app import App
from kivy.graphics import Color, Rectangle
from kivy.uix.floatlayout import FloatLayout
from kivy.graphics.context_instructions import Color
from kivy.config import Config
from kivy.uix.image import Image
from kivy.uix.button import Button
class Panel(FloatLayout):
def __init__(self, **kw):
super(Panel, self).__init__(**kw)
self.size = (1000, 1000)
# Make the background solid white
color = Color(1.0, 1.0, 1.0, 1.0)
self.canvas.add(color)
rect = Rectangle(pos=self.pos, size=self.size)
self.canvas.add(rect)
dropdown = DropDown()
# Add the label
label = Label(text="Report Generator", pos_hint={'x': 0, 'y': 0.20}, size_hint=(None, None))
label.color = [0.0, 0.0, 0.0, 1.0]
label.size_hint = (1, 1)
label.font_size = 26
label.bold = True
self.add_widget(label)
choice = Button(text="Select Summary Report to Generate", pos_hint={'center_x': .5, 'center_y': .58},
size_hint=(0.6, 0.2))
choice.color = [1.0, 1.0, 1.0, 1.0]
choice.size_hint = (0.45, 0.1)
choice.font_size = 18
choice.bold = False
choice.bind(on_release=dropdown.open)
self.add_widget(choice)
btn1 = Button(text='Daily Report', font_size=18, size_hint_y=None, height=60)
btn1.color = [1, 1, 1, 1]
btn1.txt = 'Generating Daily Summary Report...'
btn1.bind(on_release=lambda btn1: dropdown.select(btn1.txt))
btn1.bind(on_release=lambda btn1: DailySummary())
dropdown.add_widget(btn1)
btn2 = Button(text='Weekly Report', font_size=18, size_hint_y=None, height=60)
btn2.color = [1, 1, 1, 1]
btn2.txt = 'Generating Weekly Summary Report...'
btn2.bind(on_release=lambda btn2: dropdown.select(btn2.txt))
btn2.bind(on_release=lambda btn2: WeeklySummary())
dropdown.add_widget(btn2)
dropdown.bind(on_select=lambda instance, x: setattr(choice, 'text', x))
class Report(App):
def build(self):
Config.set('graphics', 'width', '450')
Config.set('graphics', 'height', '250')
return Panel()
# Application Code
if __name__ == '__main__':
Report().run()