Я пытался создать калькулятор тайм-карты с помощью kivy и python, и когда у меня gui работает под управлением MacBook, кажется, что все на месте и где оно должно быть, но когда я его перетаскиваю к моему второму монитору, все больше, перемещается и перекрывается. Есть ли способ исправить это, чтобы вещи сохранили положение, которое я им дал?
Кроме того, вы могли бы заметить некоторые пустые метки, некоторые из них предназначены для вывода итогов за отработанные часы, но некоторые из них для правильного позиционирования, например, имя сотрудника и кнопки внизу. Я пытался найти способ отрегулировать размер текстовых полей, чтобы они не растягивались по экрану, а также отрегулировать отступы и интервалы слева, справа, сверху и снизу вместо того, чтобы просто добавлять интервалы и отступы для всех полей. наоборот. Поэтому мне пришлось создать дополнительные столбцы и поместить в них метки, чтобы размер текстовых полей несколько уменьшился. Я чувствую, что kivy, возможно, не лучшая структура для этого проекта, но я хотел использовать то, что, как я знал, выглядело бы хорошо, когда я закончил с этим.
python код:
from kivy import Config
Config.set('graphics', 'width', '1000')
Config.set('graphics', 'height', '700')
Config.set('graphics', 'minimum_width', '1000')
Config.set('graphics', 'minimum_height', '700')
import kivy
import kivymd
from kivymd.uix.picker import MDDatePicker
from kivymd.uix.textfield import MDTextFieldRound
from kivymd.uix.button import MDFillRoundFlatIconButton
from kivy.clock import Clock
from kivymd.theming import ThemeManager
from kivymd.app import MDApp
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
from kivymd.uix.textfield import MDTextFieldRound
from kivy.uix.scrollview import ScrollView
class HomeScreen(Screen):
pass
class MainApp(MDApp):
def __init__(self, **kwargs):
self.title = "BMI"
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Blue"
super().__init__(**kwargs)
def build(self):
self.root = Builder.load_file("main.kv")
if __name__ == "__main__":
MainApp().run()
main.kv
#:include homescreen.kv
GridLayout:
cols: 1
ScreenManager:
id: screen_manager
HomeScreen:
name: "home_screen"
id: home_screen
homescreen.kv
<HomeScreen>
FloatLayout:
ScrollView:
do_scroll_x: False
do_scroll_y: True
Label:
pos_hint: {"top": 1, "left": 1}
size_hint: 1, .1
text: "Time Card Calculator"
font_size: 75
GridLayout:
pos_hint: {"top": .9, "left": 1}
size_hint: 1, .05
cols: 4
spacing: dp(75)
padding: dp(20)
Label:
MDTextField:
hint_text: "Employee First Name"
halign: "center"
require: True
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Employee Last Name"
halign: "center"
require: True
foreground_color: 1,1,1,1
Label:
GridLayout:
cols: 3
pos_hint: {"top": .85, "left": 1}
size_hint: 1, .05
spacing: dp(50)
padding: dp(40)
MDTextField:
hint_text: "Pay start"
halign: "center"
require: True
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Pay end"
halign: "center"
require: True
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Pay date"
halign: "center"
require: True
foreground_color: 1,1,1,1
GridLayout:
cols: 9
pos_hint: {"top": .75, "left": 1}
size_hint: 1, .6
spacing: dp(30)
padding: dp(40)
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
text: "total"
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
text: "Total"
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
text: "Total"
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
MDTextField:
hint_text: "Time In"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
MDTextField:
hint_text: "Time Out"
halign: "center"
require: True
hint_text_color: 0,0,1,1
foreground_color: 1,1,1,1
Label:
GridLayout:
cols: 5
pos_hint: {"top":.15, "left": 1}
size_hint: 1, .15
spacing: dp(50)
padding: dp(40)
MDFillRoundFlatIconButton:
text: "Clear"
icon: "delete"
Label:
MDFillRoundFlatIconButton:
text: "Calculate"
icon: "calculator"
Label:
MDFillRoundFlatIconButton:
text: "Print"
icon: "printer"