wxpython窗口固定大小_除非我们在wxPython中调整窗口大小,否则Notebook小部件无法正常显示?...

即时通讯与笔记本切换有一点问题。当我切换笔记本标签时,我需要调整大小以使wigdets正确显示。我尝试过使用self.Refresh(),但似乎没有做任何事情。如果您在理解我时遇到困难,请运行以下代码,然后切换选项卡并调整大小,您会注意到存在问题,正确显示内容。我不知道这是wxPython的问题,但我认为这是与我的代码。

IMAGE_NAME = []

IMAGE_DATA = []

IMAGEMORE_NAME=[]

IMAGEMORE_DATA=[]

import sys

import wx

def deletepic(self):

try:

self.parent.bitmap.Destroy()

except:

print sys.exc_info()

def sendnewpic(self):

if self.parent.bitmap: deletepic(self)

if IMAGE_DATA[self.image_listsel] != '':

try:

print IMAGE_DATA[self.image_listsel]

bmp = wx.Image(IMAGE_DATA[self.image_listsel], wx.BITMAP_TYPE_ANY).ConvertToBitmap()

self.parent.scroll_img.SetScrollbars(1, 1, bmp.GetWidth(), bmp.GetHeight())

self.parent.bitmap = wx.StaticBitmap(self.parent.scroll_img, -1, bmp, (0, 0))

self.parent.Refresh()

except:

pass

def areachange(self, pg):

print pg

try:

if IMAGE_DATA[self.image_listsel] == '':

deletepic(self)

except:

pass

if pg == "Regular Pictures":

self.images_area.Show()

self.scroll_img.Show()

self.btnTwo.Show()

else:

self.images_area.Hide()

self.scroll_img.Hide()

self.btnTwo.Hide()

if pg == "More Pictures":

self.images_area.Show()

self.scroll_img.Show()

self.imageboxersiz.Show()

else:

self.imageboxersiz.Hide()

self.Refresh()

class imageTab(wx.Panel):

def __init__(self, parent, grandparent):

wx.Panel.__init__(self, parent)

self.parent = grandparent

self.image_listsel = 0

self.listBox = wx.ListBox(self, size=(200, -1), choices=IMAGE_NAME, style=wx.LB_SINGLE)

self.sizer = wx.BoxSizer(wx.VERTICAL)

btnSizer = wx.BoxSizer(wx.VERTICAL) #change to horizontal for side by side

self.sizerMain = wx.BoxSizer()

self.listBox.Bind(wx.EVT_LISTBOX_DCLICK, self.reName)

self.listBox.Bind(wx.EVT_LISTBOX, self.imagesel)

btn = wx.Button(self, label="Create New",size=(200, 40))

btnTwo = wx.Button(self, label="Test 2",size=(200, 40))

btn.Bind(wx.EVT_BUTTON, self.newAddImage)

self.sizer.Add(self.listBox, proportion=1, flag=wx.TOP | wx.EXPAND | wx.LEFT, border=5)

btnSizer.Add(btn, 0, wx.ALL, 5)

btnSizer.Add(btnTwo, 0, wx.ALL, 5)

self.sizer.Add(btnSizer)

self.sizerMain.Add(self.sizer, proportion=0, flag=wx.BOTTOM | wx.EXPAND, border=0)

self.SetSizer(self.sizerMain)

def imagesel(self, evt):

self.image_listsel = self.listBox.GetSelection()

sendnewpic(self)

def newAddImage(self, evt):

IMAGE_NAME.append('hi')

IMAGE_DATA.append('')

self.listBox.Set(IMAGE_NAME)

self.listBox.SetSelection(len(IMAGE_NAME)-1)

self.imagesel(None) #making it a selected image, globally

def reName(self,parent):

sel = self.listBox.GetSelection()

text = self.listBox.GetString(sel)

renamed = wx.GetTextFromUser('Rename item', 'Rename dialog', text)

if renamed != '':

IMAGE_NAME.pop(sel)

IMAGE_NAME.insert(sel,renamed)

self.listBox.Set(IMAGE_NAME)

self.listBox.SetSelection(sel)

class objectTab(wx.Panel):

def __init__(self, parent, grandparent):

wx.Panel.__init__(self, parent)

self.parent = grandparent

self.image_listsel = 0

self.listBox = wx.ListBox(self, size=(200, -1), choices=IMAGEMORE_NAME, style=wx.LB_SINGLE)

self.sizer = wx.BoxSizer(wx.VERTICAL)

btnSizer = wx.BoxSizer(wx.VERTICAL) #change to horizontal for side by side

self.sizerMain = wx.BoxSizer()

self.listBox.Bind(wx.EVT_LISTBOX_DCLICK, self.reName)

self.listBox.Bind(wx.EVT_LISTBOX, self.imagesel)

btn = wx.Button(self, label="Create New",size=(200, 40))

btnTwo = wx.Button(self, label="Test 2",size=(200, 40))

btn.Bind(wx.EVT_BUTTON, self.newAddImage)

self.sizer.Add(self.listBox, proportion=1, flag=wx.TOP | wx.EXPAND | wx.LEFT, border=5)

btnSizer.Add(btn, 0, wx.ALL, 5)

btnSizer.Add(btnTwo, 0, wx.ALL, 5)

self.sizer.Add(btnSizer)

self.sizerMain.Add(self.sizer, proportion=0, flag=wx.BOTTOM | wx.EXPAND, border=0)

self.SetSizer(self.sizerMain)

def imagesel(self, evt):

self.image_listsel = self.listBox.GetSelection()

def newAddImage(self, evt):

IMAGEMORE_NAME.append('New image')

IMAGEMORE_DATA.append('')

self.listBox.Set(IMAGEMORE_NAME)

self.listBox.SetSelection(len(IMAGEMORE_NAME)-1)

self.imagesel(None) #making it a selected image, globally

def reName(self,parent):

sel = self.listBox.GetSelection()

text = self.listBox.GetString(sel)

renamed = wx.GetTextFromUser('Rename item', 'Rename dialog', text)

if renamed != '':

IMAGEMORE_NAME.pop(sel)

IMAGEMORE_NAME.insert(sel,renamed)

self.listBox.Set(IMAGEMORE_NAME)

self.listBox.SetSelection(sel)

class MyPanel(wx.Panel):

def __init__(self, *args, **kwargs):

wx.Panel.__init__(self, *args, **kwargs)

self.notebook = wx.Notebook(self, size=(225, -1))

self.tab_images = imageTab(self.notebook, self)

self.notebook.AddPage(self.tab_images, "Regular Pictures", select=True)

self.tab_imagesmore = objectTab(self.notebook, self)

self.notebook.AddPage(self.tab_imagesmore, "More Pictures")

self.scroll_img = wx.ScrolledWindow(self, -1)

self.scroll_img.SetScrollbars(1, 1, 600, 400)

self.images_area = wx.StaticBox(self, -1, '')

self.sizerBox = wx.StaticBoxSizer(self.images_area, wx.HORIZONTAL)

self.sizerBox2 = wx.BoxSizer()

self.sizerBox.Add(self.scroll_img, 1, wx.EXPAND|wx.ALL, 10)

self.sizerBox2.Add(self.sizerBox, 1, wx.EXPAND|wx.ALL, 10)

self.sizer = wx.BoxSizer()

self.sizer.Add(self.notebook, proportion=0, flag=wx.EXPAND)

btnSizer = wx.BoxSizer(wx.VERTICAL) #change to horizontal for side by side

self.btnTwo = wx.Button(self, label="Load File", size=(200, 40))

self.bmp = None

self.bitmap = None

self.imageboxersiz=wx.ComboBox(self, -1, "None Selected!",(0, 0), (190,20),IMAGE_NAME, wx.CB_DROPDOWN)

btnSizer.Add(self.imageboxersiz, 0, wx.TOP, 15)

btnSizer.Add(self.btnTwo, 0, wx.TOP, 15)

self.sizerBox2.Add(btnSizer)

#

self.sizer.Add(self.sizerBox2, proportion=1, flag=wx.EXPAND)

self.SetSizer(self.sizer)

self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)

areachange(self, self.notebook.GetPageText(0))

def OnClickTop(self, event):

self.scroll_img.Scroll(600, 400)

def OnClickBottom(self, event):

self.scroll_img.Scroll(1, 1)

def OnPageChanged(self, event):

new = event.GetSelection()

areachange(self, self.notebook.GetPageText(new))

event.Skip()

def OnPageChanging(self, event):

event.Skip()

class MainWindow(wx.Frame):

def __init__(self, *args, **kwargs):

wx.Frame.__init__(self, *args, **kwargs)

self.panel = MyPanel(self)

self.Show()

app = wx.App(False)

win = MainWindow(None, size=(600, 400))

app.MainLoop()非常感谢你。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值