Ich habe ein Programm in ein Tab meines Notebooks geladen und es funktioniert alles. Nun wollte ich ein Menu hinzufügen. Dies geht auch, nur wird jetzt das Programm im Tab nicht mehr angezeigt, nur wenn ich das Fenster vergrössere...
Hier mal mein Code:
Code: Alles auswählen
# -*- coding: cp1252 -*-
import wx
import mol
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Lab Tools", size=(600, 600))
p = wx.Panel(self)
# Create Menu Bar
menu = wx.Menu()
exit = menu.Append(-1, "Exit")
self.Bind(wx.EVT_MENU, self.OnExit, exit)
menuBar = wx.MenuBar()
menuBar.Append(menu, "File")
self.SetMenuBar(menuBar)
# Create Notebook
nb = wx.Notebook(p)
# create the page windows as children of the notebook
page1 = mol.MyFrame(nb)
# add the pages to the notebook with the label to show on the tab
nb.AddPage(page1, "Solution Calculator")
# put the notebook in a sizer for the panel to manage the layout
sizer = wx.BoxSizer()
sizer.Add(nb, 1, wx.EXPAND)
p.SetSizer(sizer)
# functions
def OnExit(self, event):
self.Close()
if __name__ == "__main__":
app = wx.App()
MainFrame().Show()
app.MainLoop()
Code: Alles auswählen
# -*- coding: cp1252 -*-
import wx
class MyFrame(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
# Text
txt = wx.StaticText(self, -1, "Compound", pos=(10, 50))
txt = wx.StaticText(self, -1, "Example: Ba(OH)2", pos=(80, 80))
txt = wx.StaticText(self, -1, "Molarity", pos=(10, 100))
txt = wx.StaticText(self, -1, "mol / L", pos=(190, 100))
txt = wx.StaticText(self, -1, "Volume", pos=(10, 150))
txt = wx.StaticText(self, -1, "L", pos=(190, 150))
# Eingabe Felder
self.verbindung = wx.TextCtrl(self, size=(100, -1), pos=(80, 50))
self.molaritaet = wx.TextCtrl(self, size=(100, -1), pos=(80, 100))
self.volumen = wx.TextCtrl(self, size=(100, -1), pos=(80, 150))
# Buttons
btn = wx.Button(self, -1, "Ok", pos=(80, 180))
# Event Binding
self.Bind(wx.EVT_BUTTON, self.berechne, btn)
# Funktion um Werte zu holen
def get_verbindung(self, evt):
verbindung = self.verbindung.GetValue()
return verbindung
def get_molaritaet(self, evt):
molaritaet = self.molaritaet.GetValue()
return molaritaet
def get_volumen(self, evt):
volumen = self.volumen.GetValue()
return volumen
# Berechnung der Masse
def berechne(self, evt):
mm = {'BaSO4': ('Bariumsulfat', '233'), 'CaC2': ('Calciumcarbid', '64.1')}
verbindung = self.get_verbindung(evt)
molaritaet = self.get_molaritaet(evt)
volumen = self.get_volumen(evt)
molmasse = mm[verbindung][1]
masse = float(molmasse) * float(volumen) * float(molaritaet)
text = 'Weight out ' + str(masse) + ' g .'
# Ausgabe
txt = wx.StaticText(self, -1, str(text), pos=(80, 220))
Liebe Grüsse
Stefanie