我也是 Python 和 Kivy 的新手,所以我遇到了一些麻烦。
当我使用 kivy 弹出窗口显示表格时(使用“PrettyTable”模块),我得到了这张表格的损坏视图。
我的python代码:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from prettytable import PrettyTable
class GeneralForm(BoxLayout):
def RUN(self):
def TABLE():
x = PrettyTable(["City name", "Area", "Population"])
x.align["City name"] = "l" # Left align city names
x.padding_width = 1 # One space between column edges and contents (default)
x.add_row(["Adelaide",1295, 1158259])
x.add_row(["Brisbane",5905, 1857594])
return str(x)
popup = Popup(title='Test popup', content=Label(text=TABLE()), auto_dismiss=False)
popup.open()
class TimeTable(App):
def build(self):
return GeneralForm()
if __name__ == '__main__':
TimeTable().run()
我的 .kv 代码:
<GeneralForm>:
orientation: "vertical"
BoxLayout:
Button:
id: but
text: "Show!"
on_press: root.RUN()