2016-04-06 22 views
2

bir çerçeve değiştirmek? adı isim1 isim2wxPython Ben sadece kod var

"BUTTTON" 

ben "BUTONUNA" e bastıktan sonra NAME2 ile düğme arasındaki wx.TextCtrl yöntemi eklemek istiyorum: benim gerçek programda Ben böyle bir şey var. Bir çerçeveyi modifiye etmem gerekiyor (beetwen name2 ve button ekle). Bunu nasıl başarabilirim bilmiyorum.

EDIT.

def __init__(self, parent): 
    global odstep 
    self.panel = wx.Panel.__init__(self, parent) 
    odstep = 0 
    odstep1 = 0 
    font = wx.Font(13, wx.DEFAULT, wx.NORMAL, wx.NORMAL) 
    for name in config['rewir1']: 
     nazwa_zliczana = config['rewir1'][name] 
     odstep += 22 
     self.name1 = wx.StaticText(self, -1, name, (300, 10 + odstep)) 
     self.name1.SetFont(font) 
     btn_usuwanie = wx.Button(self, -1, u"Usuń", (475, 10 + odstep)) 
     self.Bind(wx.EVT_BUTTON, lambda evt, i: Program.Usuwanie(evt, i), btn_usuwanie) 
    wx.StaticText(self, -1, 'PART I', (365, 0), style=wx.ALIGN_CENTER).SetFont(font) 
    odstep1 = odstep + 50 
    print odstep 
    for name in config['rewir2']: 
     nazwa_zliczana = config['rewir2'][name] 
     odstep1 += 22 
     self.name2 = wx.StaticText(self, -1, name, (300, 50 + odstep1)) 
     self.name2.SetFont(font) 
     btn_usuwanie_2 = wx.Button(self, -1, u"Usuń", (475, 50 + odstep1)) 
     self.Bind(wx.EVT_BUTTON, lambda evt, i: Program.Usuwanie(evt, i), btn_usuwanie_2) 
    print odstep1 
    wx.StaticText(self, -1, 'PART II', (365, 80 + odstep), style=wx.ALIGN_CENTER).SetFont(font) 
    self.btn = wx.Button(self, -1, "Change panel", (345, 500)) 
    self.btn_dodaj_rewir1 = wx.Button(self, -1, "Add name", (345, 42 + odstep)) 
    self.btn_dodaj_rewir2 = wx.Button(self, -1, "Add name", (345, 84 + odstep1)) 
    self.Bind(wx.EVT_BUTTON, self.new_name, self.btn_dodaj_rewir1) 

cevap

1
  • instanced wx.StaticText kaydetmek Sen gerekir: Ben değiştirmeniz gereken bir kod vardır. Daha sonra özelliklerini değiştirmek için.
    • Konumu değiştirmek için SetPosition yöntemini kullanın. Olay işleyicisine (change_pos aşağıdaki kod) olay EVT_BUTTON olayını bağlamak için
  • .

class Glowne(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent=parent) 
     tekst = 'HELLO - position' 
     font = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.NORMAL) 
     self.text = wx.StaticText(self, -1, tekst, (300, 55)) # Save for later use 
     self.text.SetFont(font) 

     btn = wx.Button(self, -1, "Change pos", (345, 100)) 
     btn.Bind(wx.EVT_BUTTON, self.change_pos) 

    def change_pos(self, event): 
     x, y = self.text.Position 
     self.text.SetPosition((x, y + 10)) 
+0

başka sorun var. Programımda bir döngü var. Tüm öğelerin yerlerini değiştirmem gerekiyor. SetPosition'ı kullandığımda, döngüden yalnızca sonuncu öğeyi alır. Herhangi bir fikir? – jundymek

+0

@Luk, Sorununuzu gösteren bir kodla yeni bir soru daha yayınlayabilir misiniz? – falsetru

+0

Sorumu değiştirdim ve bazı kodları ekledim. Yeni konu başlamalı mıyım? – jundymek