我用 wxPython 编写了一个程序。我们在许多具有不同显示配置的不同计算机上运行该程序。
例子:
1920x1080,DPI 100%
3000x2000,DPI 175%
1980x1080,DPI 150%(小型 13" 显示笔记本电脑)
我在全高清、DPI 100% 显示器上编码 - GUI 看起来不错!特别是在 3000x2000 上。TextCtrls、BitmapButtons 和Images 通常会改变它们的大小(它们变得更小)并且GUI 因不同的分辨率而变得混乱。DPI 150% 相同。
我试图通过在我的主类中设置我的进程的 DPI 意识来防止它,但这并不能始终如一地工作。
以下是我设置 DPI 意识的方式:
import ctypes
# Query DPI Awareness (Windows 10 and 8)
awareness = ctypes.c_int()
errorCode = ctypes.windll.shcore.GetProcessDpiAwareness(0, ctypes.byref(awareness))
# Set DPI Awareness (Windows 10 and 8)
errorCode = ctypes.windll.shcore.SetProcessDpiAwareness(2)
Run Code Online (Sandbox Code Playgroud)
题:
我将附上一个代码示例,其中我尝试尽可能多地进行大小和定位,以便为你们提供可能修复某些问题的基础。
import wx
import wx.adv
class Mywin(wx.Frame):
def __init__(self,parent,title):
wx.Frame.__init__(self, parent, wx.ID_ANY, …
Run Code Online (Sandbox Code Playgroud) 我写了一段代码,其中有一个带有画布的简单 GUI。在这块画布上我画了一个 Matplot。Matplot 每秒都会使用来自 SQ Lite DB 的数据进行更新,我在其中填充了一些虚假的传感器信息(目前仅用于测试)。
我的问题是画布的重绘导致我的窗口/gui 每秒都滞后。我什至尝试在另一个线程中更新情节。但即使在那里我也会出现滞后。
有了我最新的代码,我的大部分工作就完成了。线程有助于防止我的 GUI/窗口在画布更新时冻结。
我最不想念的就是使其线程安全。
这是我收到的消息:
RuntimeError: main thread is not in main loop
Run Code Online (Sandbox Code Playgroud)
这是我最新的线程工作代码:
from tkinter import *
import random
from random import randint
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import time
import threading
from datetime import datetime
continuePlotting = False
def change_state():
global continuePlotting
if continuePlotting == True:
continuePlotting = False
else:
continuePlotting = True
def data_points():
yList = []
for x in range (0, 20):
yList.append(random.randint(0, 100)) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个 CheckListCtrl,您可以通过单击其标题对列中的所有数据进行排序。
在我的代码的基本示例中,我将在下面发布我将“行”设置为元组列表,因为在我的最终版本中,ListCtrl 将显示 SQLite 查询的结果。
到目前为止,我的代码存在的问题:
我self.itemDataMap = rows
认为我用错了,如果我尝试排序,我会收到此错误消息:TypeError: list indices must be integers or slices, not tuple
。那么我如何将它与元组列表而不是字典一起使用?
import wx
import wx.lib.mixins.listctrl as listmix
from wx.lib.agw import ultimatelistctrl as ULC
APPNAME='Sortable Ultimate List Ctrl'
APPVERSION='1.0'
MAIN_WIDTH=300
MAIN_HEIGHT=300
class TestUltimateListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS, size=(MAIN_WIDTH,MAIN_HEIGHT))
self.index = 0
self.list_ctrl = ULC.UltimateListCtrl(self, -1, agwStyle=ULC.ULC_REPORT|ULC.ULC_HAS_VARIABLE_ROW_HEIGHT)
self.list_ctrl.InsertColumn(0, "Make")
self.list_ctrl.InsertColumn(1, "Model")
self.list_ctrl.InsertColumn(2, "Year")
self.list_ctrl.InsertColumn(3, "Color")
rows = [("Ford", "Taurus", "1996", "Blue"),
("Nissan", "370Z", "2010", "Green"),
("Porche", …
Run Code Online (Sandbox Code Playgroud) 我想通过用两个不同的字符串构造一个变量来获取变量的值.
把它分解到最低限度:
TA = 1
TB = 2
TC = 3
B = 2
Messagebox.Show(B*("T"+"B"))
Run Code Online (Sandbox Code Playgroud)
我知道这是最小的,我不想在复杂的代码中使用它.我也知道有办法做到这一点,但我在一个功能最少的环境中工作.
那么有一个基本的方法吗?