Moje pierwsze okienko:
import wx app = wx.App() frame = wx.Frame(None, -1, "Tytul") frame.Show() app.MainLoop()
Drugie okienko z potwierdzeniem wyjścia
import wx def OnClose(event): dlg = wx.MessageDialog(top, "Naprawdę chcesz to, kurna, zamknąć?", "Co jest?!", wx.OK|wx.CANCEL|wx.ICON_QUESTION) result = dlg.ShowModal() dlg.Destroy() if result == wx.ID_OK: top.Destroy() app = wx.App(redirect=True) top = wx.Frame(None, title="Hello World", size=(300,200)) top.Bind(wx.EVT_CLOSE, OnClose) top.Show() app.MainLoop()
Trzecie okno z klasą
import wx class windowClass(wx.Frame): def __init__(self, parent, title): super(windowClass, self).__init__(parent, title=title, size=(400, 300)) self.Move(100, 500) # pozycja okna 100, 500 self.Center() # pozycja okna w środku self.Show() app = wx.App() windowClass(None, title="Joł, joł") app.MainLoop()
Okno z menu
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ZetCode wxPython tutorial This example shows a simple menu. author: Jan Bodnar website: www.zetcode.com last modified: April 2018 """ import wx class Example(wx.Frame): def __init__(self, *args, **kwargs): super(Example, self).__init__(*args, **kwargs) self.InitUI() def InitUI(self): menubar = wx.MenuBar() fileMenu = wx.Menu() fileItem = fileMenu.Append(wx.ID_EXIT, 'Quit', 'Quit application') menubar.Append(fileMenu, '&File') self.SetMenuBar(menubar) self.Bind(wx.EVT_MENU, self.OnQuit, fileItem) self.SetSize((300, 200)) self.SetTitle('Simple menu') self.Centre() def OnQuit(self, e): self.Close() def main(): app = wx.App() ex = Example(None) ex.Show() app.MainLoop() if __name__ == '__main__': main()
wxPython tutorial – Jan Bodnar
You can check your virtual environment in PyCharm -> Preferences -> Project -> Project Interpreter. There you can also press the + symbol at the bottom left to install wxpython there. (Which will basically pip install the package inside the virtualenv your project uses.)