Python Forum
How to use an Emulator and a MttQ broker?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use an Emulator and a MttQ broker?
#14
Python disagrees that pymongo is installed. Which version of Python are you using? What is your OS? How did you install pymongo?

Did you do all the GPIO setup at the start of the program? All of this stuff has to happen before you call mainloop()
GPIO.setmode(GPIO.BCM)
GPIO.setup(Ent,GPIO.OUT)
GPIO.setwarnings(False)
window.show() is how you have a hidden window drawn to the screen, but it is for Qt, not tkinter. My mistake. Here's a working example of how I think the histo window should work.
import tkinter as tk
import datetime

class Histo(tk.Toplevel):
    """A window for viewing log messages"""
    def __init__(self):
        super().__init__()
        self.title('Historique')  
        self.text = tk.Text(self, width=40, height=10)
        self.text.pack(padx=5, pady=5)
 
    def log(self, msg):
        """Append log message to text"""
        now = datetime.datetime.now()
        self.text.insert(tk.INSERT, f"{now} {msg}\n")

class MainWindow(tk.Tk):
    def __init__(self):
        super().__init__()
        self.histo = Histo()
        self.histo.withdraw()
        button = tk.Button(self, text="Press Me", command=self.show_histo)
        button.pack(padx=20, pady=20)

    def show_histo(self):
        self.histo.log("Show histo")
        self.histo.deiconify()

MainWindow().mainloop()
Here I combined logging and drawing the window. Your app will do logging for on/off events and draw the panel when the afficher button is pressed.
Reply


Messages In This Thread
RE: How to use an Emulator and a MttQ broker? - by deanhystad - Jul-04-2022, 05:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyautogui with a display emulator? gumby4231 0 2,634 Jul-30-2020, 02:46 PM
Last Post: gumby4231
  running python script from shell invoked with os.system("x-terminal-emulator -e /bin/ markhaus 2 3,121 Feb-21-2019, 11:55 PM
Last Post: markhaus

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020