gpt4 book ai didi

python - WxPython - 添加新内容时调整 WxFrame 大小?

转载 作者:行者123 更新时间:2023-12-01 06:15:01 25 4
gpt4 key购买 nike

正如听起来的那样。我在 Wx.Frame 中有一些动态创建的按钮,我希望父框架在添加新按钮时增加高度。高度已经通过按钮总数乘以等于每个按钮高度的整数来获取,但我不知道如何让框架在添加新按钮时根据该值更改大小。

作为一个附带问题,我当前更新按钮的方法会产生令人讨厌的闪烁,我想知道是否有人有任何解决该问题的想法。

import wx
import mmap
import re

class pt:
with open('note.txt', "r+") as note:
buf = mmap.mmap(note.fileno(), 0)
TL = 0
readline = buf.readline
while readline():
TL += 1
readlist = note.readlines()
note.closed

class MainWindow(wx.Frame):

def __init__(self, parent, title):
w, h = wx.GetDisplaySize()
self.x = w * 0
self.y = h - bdepth

self.container = wx.Frame.__init__(self, parent, title = title, pos = (self.x, self.y), size = (224, bdepth), style = wx.STAY_ON_TOP)


self.__DoButtons()

self.Show(True)

def __DoButtons(self):

for i, line in enumerate(pt.readlist):

strip = line.rstrip('\n')
todo = strip.lstrip('!')

self.check = re.match('!', strip)
self.priority = re.search('(\!$)', strip)

if self.check is None and self.priority is None:
bullet = wx.Image('bullet.bmp', wx.BITMAP_TYPE_BMP)

solid = wx.EmptyBitmap(200,64,-1)
dc = wx.MemoryDC()
dc.SelectObject(solid)
solidpen = wx.Pen(wx.Colour(75,75,75),wx.SOLID)
dc.SetPen(solidpen)
dc.DrawRectangle(0, 0, 200, 64)
dc.SetTextForeground(wx.Colour(255, 255, 255))
dc.DrawBitmap(wx.BitmapFromImage(bullet, 32), 10, 28)
dc.DrawText(todo, 30, 24)
dc.SelectObject(wx.NullBitmap)

hover = wx.EmptyBitmap(200,64,-1)
dc = wx.MemoryDC()
dc.SelectObject(hover)
hoverpen = wx.Pen(wx.Colour(100,100,100),wx.SOLID)
dc.SetPen(hoverpen)
dc.DrawRectangle(0, 0, 200, 64)
dc.SetTextForeground(wx.Colour(255, 255, 255))
dc.DrawBitmap(wx.BitmapFromImage(bullet, 32), 10, 28)
dc.DrawText(todo, 30, 24)
dc.SelectObject(wx.NullBitmap)

bmp = solid

elif self.priority is None:
checkmark = wx.Image('check.bmp', wx.BITMAP_TYPE_BMP)

checked = wx.EmptyBitmap(200,64,-1)
dc = wx.MemoryDC()
dc.SelectObject(checked)
checkedpen = wx.Pen(wx.Colour(50,50,50),wx.SOLID)
dc.SetPen(checkedpen)
dc.DrawRectangle(0, 0, 200, 50)
dc.SetTextForeground(wx.Colour(200, 255, 0))
dc.DrawBitmap(wx.BitmapFromImage(checkmark, 32), 6, 24)
dc.DrawText(todo, 30, 24)
dc.SelectObject(wx.NullBitmap)

bmp = checked

else:
exclaim = wx.Image('exclaim.bmp', wx.BITMAP_TYPE_BMP)

important = wx.EmptyBitmap(200,64,-1)
dc = wx.MemoryDC()
dc.SelectObject(important)
importantpen = wx.Pen(wx.Colour(75,75,75),wx.SOLID)
dc.SetPen(importantpen)
dc.DrawRectangle(0, 0, 200, 50)
dc.SetTextForeground(wx.Colour(255, 180, 0))
dc.DrawBitmap(wx.BitmapFromImage(exclaim, 32), 6, 24)
dc.DrawText(todo, 30, 24)
dc.SelectObject(wx.NullBitmap)

importanthover = wx.EmptyBitmap(200,64,-1)
dc = wx.MemoryDC()
dc.SelectObject(importanthover)
importanthoverpen = wx.Pen(wx.Colour(100,100,100),wx.SOLID)
dc.SetPen(importanthoverpen)
dc.DrawRectangle(0, 0, 200, 50)
dc.SetTextForeground(wx.Colour(255, 180, 0))
dc.DrawBitmap(wx.BitmapFromImage(exclaim, 32), 6, 24)
dc.DrawText(todo, 30, 24)
dc.SelectObject(wx.NullBitmap)

bmp = important

b = wx.BitmapButton(self, i + 800, bmp, (10, i * 64), (bmp.GetWidth(), bmp.GetHeight()), style = wx.NO_BORDER)


if self.check is None and self.priority is None:
b.SetBitmapHover(hover)
elif self.priority is None:
b.SetBitmapHover(checked)
else:
b.SetBitmapHover(importanthover)

self.input = wx.TextCtrl(self, -1, "", (16, pt.TL * 64 + 4), (184, 24))
self.Bind(wx.EVT_TEXT_ENTER, self.OnEnter, self.input)

def OnClick(self, event):
button = event.GetEventObject()
button.None
print('cheese')

def OnEnter(self, event):
value = self.input.GetValue()
pt.readlist.append('\n' + value)

self.__DoButtons()

with open('note.txt', "r+") as note:
for item in pt.readlist:
note.write("%s" % item)
note.closed

bdepth = pt.TL * 64 + 32
app = wx.App(False)
frame = MainWindow(None, "Sample editor")
app.SetTopWindow(frame)
app.MainLoop()

最佳答案

据我所知,无法自动调整框架大小,但您可以使用 SetSize() 手动重置框架的大小

例如

w, h = self.GetClientSize()
self.SetSize((w, h + height_of_your_new_button))

为了以最小的麻烦获得所需的结果,您需要使用大小调整器,我认为没有充分的理由使用绝对定位。我还建议使用面板,它提供小部件之间的选项卡遍历和布局的跨平台一致性。

<小时/>

Zetcode Sizer Tutorial

wxPython Sizer Tutorial

关于python - WxPython - 添加新内容时调整 WxFrame 大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3740640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com