【问题标题】:kivy layout: different computer different displaykivy布局:不同电脑不同显示
【发布时间】:2019-01-22 18:02:51
【问题描述】:

python 布局的相同代码返回不同的 GUI。我很困惑:

# ---------- VQCIA.kv  ----------

VQCIA:

<VQCIA>:
    orientation: "vertical"
    goi: goi
    padding: 10
    spacing: 10
    size: 400, 200
    pos: 200, 200
    size_hint:None,None

    BoxLayout:
        Label:
            text: "Enter gene of interest with TAIR ID:"
            font_size: '25sp'

    BoxLayout: 
        TextInput:
            hint_text: 'AT3G20770'
            multiline: False
            font_size: '25sp'
            id: goi

    BoxLayout:
        Button:
            text: "Submit"
            size_hint_x: 15
            on_press: root.submit_goi()

# ---------- vqcia.py  ----------

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty 

class VQCIA(BoxLayout):

    # Connects the value in the TextInput widget to these
    # fields
    goi = ObjectProperty()

    def submit_goi(self):

        # Get the student name from the TextInputs
        goi = self.goi.text
        print goi
        return


class VQCIAApp(App):
    def build(self):
        return VQCIA()


dbApp = VQCIAApp()
dbApp.run()

我的实验室计算机是带有 Kivy==1.10.1 的 macOS Sierra 10.12.6 并且具有理想的输出:

另一方面,我的个人 Mac macOS high Sierra 10.13.6 with Kivy==1.10.1 输出错误:

会发生什么?

【问题讨论】:

  • 你明白,经常收到支票和取消支票是不舒服的,我认为它很吵,它会消除帮助你的愿望,避免吵闹。
  • 对此感到抱歉。我是使用堆栈溢出的新手。我以为我可以接受多个答案,但后来我意识到,一旦我接受一个答案,它就会取消另一个答案。再次抱歉。
  • 如果您有其他问题,请不要在 cmets 部分进行,它们仅用于讨论当前问题,如果您有其他问题,请创建新的 POST,如果您不想引起更多问题,阅读How to Ask并通过tour
  • 感谢您的建议。抱歉操作不当。

标签: python layout kivy


【解决方案1】:
  1. 尝试使用与密度无关的像素,dp
  2. 在 kv 文件中,有两个根。有一个根规则 VQCIA: 和一个类规则 &lt;VQCIA&gt;: 用于根。因为在 Python 代码中,它使用return VQCIA(),它与类规则相关联,在 kv 文件中 &lt;VQCIA&gt;:。因此,请删除根规则 VQCIA: 以避免混淆。

kv 文件 - vqcia.kv

<VQCIA>:    # class rule for root widget
    orientation: "vertical"
    goi: goi
    padding: dp(10)
    spacing: dp(10)
    size: dp(400), dp(200)
    pos: dp(200), dp(200)
    size_hint: None, None

Dimensions

dp

与密度无关的像素 - 基于 屏幕的物理密度。密度为 1 时,1dp 等于 1像素。在更高密度的屏幕上运行时,像素数 用于绘制 1dp 的比例放大了适合屏幕的系数 dpi,而较低的 dpi 则相反。 dp 与像素的比率将 随屏幕密度变化,但不一定直接 部分。使用 dp 单元是制作视图的简单解决方案 布局中的尺寸为不同的屏幕正确调整大小 密度。换句话说,它为现实世界提供了一致性 跨不同设备的 UI 大小。

sp

Scale-independent Pixels - 这就像 dp 单位,但它也是 按用户的字体大小偏好缩放。我们建议您使用这个 指定字体大小时的单位,因此字体大小将调整为 屏幕密度和用户偏好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 2016-07-04
    • 2014-07-27
    • 2019-03-20
    • 1970-01-01
    相关资源
    最近更新 更多