From 694b2472d75588666e4d2deb010fa87f8b48bebf Mon Sep 17 00:00:00 2001 From: weijian Date: Mon, 17 Apr 2023 15:14:32 +0800 Subject: [PATCH] Fix GUI program tk module calling problem --- mecharm/mecharm/scripts/simple_gui.py | 5 ++++- mecharm/mecharm_pi/scripts/simple_gui.py | 8 +++++--- mycobot_280/mycobot_280/scripts/simple_gui.py | 11 +++++++---- mycobot_280/mycobot_280arduino/scripts/simple_gui.py | 11 +++++++---- mycobot_280/mycobot_280jn/scripts/simple_gui.py | 8 +++++--- mycobot_280/mycobot_280pi/scripts/simple_gui.py | 8 +++++--- .../mycobot_320/scripts/mycobot_320_simple_gui.py | 7 +++++-- .../new_mycobot_320/scripts/mycobot_320_simple_gui.py | 7 +++++-- .../scripts/mycobot_320_simple_gui.py | 9 ++++++--- .../mypalletizer_260/scripts/simple_gui.py | 7 +++++-- .../mypalletizer_260_pi/scripts/simple_gui.py | 7 +++++-- 11 files changed, 59 insertions(+), 29 deletions(-) diff --git a/mecharm/mecharm/scripts/simple_gui.py b/mecharm/mecharm/scripts/simple_gui.py index 387718d..f8ed58e 100755 --- a/mecharm/mecharm/scripts/simple_gui.py +++ b/mecharm/mecharm/scripts/simple_gui.py @@ -1,6 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import Tkinter as tk +try: + import tkinter as tk +except ImportError: + import Tkinter as tk from mycobot_communication.srv import GetCoords, SetCoords, GetAngles, SetAngles, GripperStatus import rospy import time diff --git a/mecharm/mecharm_pi/scripts/simple_gui.py b/mecharm/mecharm_pi/scripts/simple_gui.py index c7e76cf..f8ed58e 100644 --- a/mecharm/mecharm_pi/scripts/simple_gui.py +++ b/mecharm/mecharm_pi/scripts/simple_gui.py @@ -1,7 +1,9 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # -*- coding: utf-8 -*- -# import Tkinter as tk # python2 -import tkinter as tk +try: + import tkinter as tk +except ImportError: + import Tkinter as tk from mycobot_communication.srv import GetCoords, SetCoords, GetAngles, SetAngles, GripperStatus import rospy import time diff --git a/mycobot_280/mycobot_280/scripts/simple_gui.py b/mycobot_280/mycobot_280/scripts/simple_gui.py index 9f4c791..783e3e4 100644 --- a/mycobot_280/mycobot_280/scripts/simple_gui.py +++ b/mycobot_280/mycobot_280/scripts/simple_gui.py @@ -1,6 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import Tkinter as tk +try: + import tkinter as tk +except ImportError: + import Tkinter as tk from mycobot_communication.srv import GetCoords, SetCoords, GetAngles, SetAngles, GripperStatus import rospy import time @@ -31,9 +34,9 @@ class Window: self.hs = self.win.winfo_screenheight() # height of the screen # calculate x and y coordinates for the Tk root window # 计算 Tk 根窗口的 x 和 y 坐标 - x = (self.ws / 2) - 190 - y = (self.hs / 2) - 250 - self.win.geometry("430x370+{}+{}".format(x, y)) + x = int((self.ws / 2) - 190) + y = int((self.hs / 2) - 250) + self.win.geometry("430x400+{}+{}".format(x, y)) # layout,布局 self.set_layout() # input section,输入部分 diff --git a/mycobot_280/mycobot_280arduino/scripts/simple_gui.py b/mycobot_280/mycobot_280arduino/scripts/simple_gui.py index f1eccc6..e06f6b4 100644 --- a/mycobot_280/mycobot_280arduino/scripts/simple_gui.py +++ b/mycobot_280/mycobot_280arduino/scripts/simple_gui.py @@ -1,6 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import Tkinter as tk +try: + import tkinter as tk +except ImportError: + import Tkinter as tk from mycobot_communication.srv import GetCoords, SetCoords, GetAngles, SetAngles, GripperStatus import rospy import time @@ -30,9 +33,9 @@ class Window: self.ws = self.win.winfo_screenwidth() # width of the screen self.hs = self.win.winfo_screenheight() # height of the screen # calculate x and y coordinates for the Tk root window - x = (self.ws / 2) - 190 - y = (self.hs / 2) - 250 - self.win.geometry("430x370+{}+{}".format(x, y)) + x = int((self.ws / 2) - 190) + y = int((self.hs / 2) - 250) + self.win.geometry("430x400+{}+{}".format(x, y)) # 布局 self.set_layout() # 输入部分 diff --git a/mycobot_280/mycobot_280jn/scripts/simple_gui.py b/mycobot_280/mycobot_280jn/scripts/simple_gui.py index 41f9258..bd4fcdd 100755 --- a/mycobot_280/mycobot_280jn/scripts/simple_gui.py +++ b/mycobot_280/mycobot_280jn/scripts/simple_gui.py @@ -1,7 +1,9 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # -*- coding: utf-8 -*- -# import Tkinter as tk -import tkinter as tk +try: + import tkinter as tk +except ImportError: + import Tkinter as tk from mycobot_communication.srv import GetCoords, SetCoords, GetAngles, SetAngles, GripperStatus import rospy import time diff --git a/mycobot_280/mycobot_280pi/scripts/simple_gui.py b/mycobot_280/mycobot_280pi/scripts/simple_gui.py index 41f9258..bd4fcdd 100755 --- a/mycobot_280/mycobot_280pi/scripts/simple_gui.py +++ b/mycobot_280/mycobot_280pi/scripts/simple_gui.py @@ -1,7 +1,9 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # -*- coding: utf-8 -*- -# import Tkinter as tk -import tkinter as tk +try: + import tkinter as tk +except ImportError: + import Tkinter as tk from mycobot_communication.srv import GetCoords, SetCoords, GetAngles, SetAngles, GripperStatus import rospy import time diff --git a/mycobot_320/mycobot_320/scripts/mycobot_320_simple_gui.py b/mycobot_320/mycobot_320/scripts/mycobot_320_simple_gui.py index a3626a0..e06f6b4 100755 --- a/mycobot_320/mycobot_320/scripts/mycobot_320_simple_gui.py +++ b/mycobot_320/mycobot_320/scripts/mycobot_320_simple_gui.py @@ -1,6 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import Tkinter as tk +try: + import tkinter as tk +except ImportError: + import Tkinter as tk from mycobot_communication.srv import GetCoords, SetCoords, GetAngles, SetAngles, GripperStatus import rospy import time @@ -32,7 +35,7 @@ class Window: # calculate x and y coordinates for the Tk root window x = int((self.ws / 2) - 190) y = int((self.hs / 2) - 250) - self.win.geometry("430x370+{}+{}".format(x, y)) + self.win.geometry("430x400+{}+{}".format(x, y)) # 布局 self.set_layout() # 输入部分 diff --git a/mycobot_320/new_mycobot_320/scripts/mycobot_320_simple_gui.py b/mycobot_320/new_mycobot_320/scripts/mycobot_320_simple_gui.py index f21dad1..7454cad 100755 --- a/mycobot_320/new_mycobot_320/scripts/mycobot_320_simple_gui.py +++ b/mycobot_320/new_mycobot_320/scripts/mycobot_320_simple_gui.py @@ -1,6 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import Tkinter as tk +try: + import tkinter as tk +except ImportError: + import Tkinter as tk from mycobot_communication.srv import GetCoords, SetCoords, GetAngles, SetAngles, GripperStatus import rospy import time @@ -32,7 +35,7 @@ class Window: # calculate x and y coordinates for the Tk root window x = (self.ws / 2) - 190 y = (self.hs / 2) - 250 - self.win.geometry("430x400+{}+{}".format(x, y)) + self.win.geometry("430x400+{}+{}".format(int(x), int(y))) # 布局 self.set_layout() # 输入部分 diff --git a/mycobot_320/new_mycobot_320_pi/scripts/mycobot_320_simple_gui.py b/mycobot_320/new_mycobot_320_pi/scripts/mycobot_320_simple_gui.py index 7aa7e69..7454cad 100755 --- a/mycobot_320/new_mycobot_320_pi/scripts/mycobot_320_simple_gui.py +++ b/mycobot_320/new_mycobot_320_pi/scripts/mycobot_320_simple_gui.py @@ -1,6 +1,9 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # -*- coding: utf-8 -*- -import tkinter as tk +try: + import tkinter as tk +except ImportError: + import Tkinter as tk from mycobot_communication.srv import GetCoords, SetCoords, GetAngles, SetAngles, GripperStatus import rospy import time @@ -32,7 +35,7 @@ class Window: # calculate x and y coordinates for the Tk root window x = (self.ws / 2) - 190 y = (self.hs / 2) - 250 - self.win.geometry("430x400+{}+{}".format(x, y)) + self.win.geometry("430x400+{}+{}".format(int(x), int(y))) # 布局 self.set_layout() # 输入部分 diff --git a/mypalletizer_260/mypalletizer_260/scripts/simple_gui.py b/mypalletizer_260/mypalletizer_260/scripts/simple_gui.py index 2d33ced..247665c 100644 --- a/mypalletizer_260/mypalletizer_260/scripts/simple_gui.py +++ b/mypalletizer_260/mypalletizer_260/scripts/simple_gui.py @@ -1,6 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import Tkinter as tk +try: + import tkinter as tk +except ImportError: + import Tkinter as tk from mypalletizer_communication.srv import GetCoords, SetCoords, GetAngles, SetAngles, GripperStatus import rospy import time @@ -33,7 +36,7 @@ class Window: # 计算 Tk 根窗口的 x 和 y 坐标 x = (self.ws / 2) - 190 y = (self.hs / 2) - 250 - self.win.geometry("430x350+{}+{}".format(x, y)) + self.win.geometry("430x400+{}+{}".format(int(x), int(y))) # layout. 布局 self.set_layout() # input. 输入部分 diff --git a/mypalletizer_260/mypalletizer_260_pi/scripts/simple_gui.py b/mypalletizer_260/mypalletizer_260_pi/scripts/simple_gui.py index 2d33ced..247665c 100644 --- a/mypalletizer_260/mypalletizer_260_pi/scripts/simple_gui.py +++ b/mypalletizer_260/mypalletizer_260_pi/scripts/simple_gui.py @@ -1,6 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import Tkinter as tk +try: + import tkinter as tk +except ImportError: + import Tkinter as tk from mypalletizer_communication.srv import GetCoords, SetCoords, GetAngles, SetAngles, GripperStatus import rospy import time @@ -33,7 +36,7 @@ class Window: # 计算 Tk 根窗口的 x 和 y 坐标 x = (self.ws / 2) - 190 y = (self.hs / 2) - 250 - self.win.geometry("430x350+{}+{}".format(x, y)) + self.win.geometry("430x400+{}+{}".format(int(x), int(y))) # layout. 布局 self.set_layout() # input. 输入部分