ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

avalice's profile - activity

2019-02-12 10:31:47 -0500 received badge  Famous Question (source)
2019-02-12 10:31:47 -0500 received badge  Notable Question (source)
2019-02-12 10:31:47 -0500 received badge  Popular Question (source)
2018-08-27 10:46:14 -0500 commented answer How to run rospy.spin() and Tkinter.mainloop() at the same time?

Thank you! That solved my issue!

2018-08-27 10:46:04 -0500 marked best answer How to run rospy.spin() and Tkinter.mainloop() at the same time?

Hello,

I'm trying to learn ROS by writing a really simple group-chat program in Python 2.7, Tkinter and ROS Kinetic.

I built a simple GUI on Tkinter that will publish the Entry's value to the topic when the user presses Enter.

I am stuck on this issue, where I need to run both rospy.spin() in order to subscribe to the topic, and Tkinter.mainloop(), in order for the GUI to work.

May I know how do I run both at the same time? From what I understand they each halt the program.

#!/usr/bin/env python

import rospy
import Tkinter as tk
from std_msgs.msg import String

def send(event):
        pub = rospy.Publisher("chat", String, queue_size=10)
        rospy.loginfo("attempting to send: " + entry_field.get())
        pub.publish(entry_field.get())
        entry_field.delete(0, "end")

def receive(msg):
        rospy.loginfo(rospy.get_caller_id() + msg)

if __name__ == "__main__":
        rospy.init_node("chat", anonymous=True)
        rospy.Subscriber("lets_talk", String, receive)

        root = tk.Tk()
        root.title("Let's chat!")

        msg_frame = tk.Frame(root)
        msg_frame.pack()

        msg_list = tk.Listbox(msg_frame, height=30, width=100)
        msg_list.pack()

        entry_field = tk.Entry(root)
        entry_field.bind("<Return>", send)
        entry_field.pack()

        tk.mainloop()
        rospy.spin()
2018-08-27 10:46:04 -0500 received badge  Scholar (source)
2018-08-27 10:46:04 -0500 received badge  Supporter (source)
2018-08-27 10:36:39 -0500 asked a question How to run rospy.spin() and Tkinter.mainloop() at the same time?

How to run rospy.spin() and Tkinter.mainloop() at the same time? Hello, I'm trying to learn ROS by writing a really sim