Hallo miteinander
Ich bin ein TicTacToe am erstellen, als kleines Starterprojekt.
Dafür verwende ich ToggleButtons.
Nun weiss ich nicht, welche Funktion ich verwenden kann, um eine positive Flanke zu erkennen (für eine einmalige Textausgabe, wenn ein Button gedrückt wird).
Ausserdem möchte ich nach Beendigung des Spieles die ToggleButtons wieder in ihrem Anfangszustand setzten können.
Für Hilfe wäre ich sehr dankbar.
ToggleButtons entsperren
- __blackjack__
- User
- Beiträge: 13232
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
Ob der Button eingerastet ist oder nicht, kann man sowohl vom Ereignis abfragen (`IsChecked()`) als auch vom Button-Objekt selbst (`GetValue()`).
Code: Alles auswählen
#!/usr/bin/env python3
import wx
def main():
app = wx.App()
frame = wx.Frame(None)
sizer = wx.BoxSizer(wx.VERTICAL)
toggle_button = wx.ToggleButton(frame, wx.ID_ANY, "Push me!")
toggle_button.Bind(
wx.EVT_TOGGLEBUTTON, lambda event: print(event.IsChecked())
)
sizer.Add(toggle_button)
frame.SetSizer(sizer)
frame.Show()
app.MainLoop()
if __name__ == "__main__":
main()
Please call it what it is: copyright infringement, not piracy. Piracy takes place in international waters, and involves one or more of theft, murder, rape and kidnapping. Making an unauthorized copy of a piece of software is not piracy, it is an infringement of a government-granted monopoly.