How do I get a message box in Python 2.7.5 - python

>>> from Tkinter import tkMessageBox
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
from Tkinter import tkMessageBox
ImportError: cannot import name tkMessageBox
I am getting this error, even though from Tkinter import * is working fine. I am using Python 2.7.5.

tkMessageBox is a module on its own, so you should import it separately:
import Tkinter
import tkMessageBox

Related

Why isn't pyinstaller making a Tkinter window?

It's important to know that I am using pyinstaller to package python.
tkinter works perfectly fine when I package it with only:
import tkinter
root=tkinter.Tk()
root.mainloop()
but when I add some more of my code it shows the error:
Traceback (most recent call last):
File "exec", line 1, in <module>
import tkinter
File "C:\Program Files\Python38\lib\tkinter\__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: Module use of python39.dll conflicts with this version of Python.
These are all my imports:
import discord
import subprocess
from os import getcwd
import os
import pyautogui
from threading import *
import sys
I tried using only a tkinter window with no extra code and that worked!
But when I add the rest of my code it shows the error:
Traceback (most recent call last):
File "exec", line 1, in \<module\>
import tkinter
File "C:\\Program Files\\Python38\\lib\\tkinter\__init_\_.py", line 36, in \<module\>
import \_tkinter # If this fails your Python may not be configured for Tk
ImportError: Module use of python39.dll conflicts with this version of Python.

Raspberry Pi Dobot Magician connection using ctypes

I've wrote some code which connects with DobotMagician and moves its arm. It was firstly made for Windows but due to some project requirements i switched to Raspberry pi 4B (windows with python 3.10 pycharm to linux with python 3.9.2 and Thonny IDE). I'm struggling to rewrite the code for Linux. I'm keep getting following error:
Traceback (most recent call last):
File "/home/XYZ/Desktop/dobot_composite/dobot_composite_demov-master/main.py", line 26, in <module>
ctypes.cdll('/michalsiniarski/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library', mode=ctypes.RTLD_GLOBAL)
TypeError: 'LibraryLoader' object is not callable
Part of code producing an error:
import os
import sys
from serial.tools import list_ports
import pandas
import ctypes
from ctypes import *
from magician_library import DoBotArm as Dbt
from magician_library import DobotDllType as dType
from magician_library import *
import numpy as np
import logging
import time
import threading
import multiprocessing
import subprocess as sub
import keyboard
homey_max=160
homex_min, homex_max=180, 274
a_max=2*homey_max
b_max=homex_max-homex_min
h_max, h_min=50, -60
resolution=1
homeX, homeY, homeZ=225, 0, h_max
#os.add_cdll_directory('/XYZ/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library')
ctypes.cdll('/XYZ/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library', mode=ctypes.RTLD_GLOBAL)
Commented out part os.add.cdll...is almost 1:1 line rewritten from Windows version (difference is cdll and dll), which also produces an error:
Traceback (most recent call last):
File "/home/XYZ/Desktop/dobot_composite/dobot_composite_demov-master/main.py", line 25, in <module>
os.add_cdll_directory('/XYZ/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library')
AttributeError: module 'os' has no attribute 'add_cdll_directory'
Guide I followed:
https://github.com/SERLatBTH/StarterGuide-Dobot-Magician-with-Python#starting-out
I'm really new to python and I don't have more ideas how to make this work or even if this possible at all :c

Is there a specific way to import openpyxl in tkinter?

I am relatively new to writing code in tkinter, so I apologize for this question. I am writing an application in tkinter, where I want to update the values in Excel based on the entries in widgets.
I have tried installing openpyxl through pip install, and a manual install. I have moved openpyxl to the folder of my project, but has not helped at all.
from tkinter import *
from tkinter import ttk
import tkinter as tk
from datetime import datetime
from tkinter import messagebox
import os
import pandas as pd
import xlrd
import xlwt
from pandas import ExcelWriter
from pandas import ExcelFile
import sqlite3
import getpass
import openpyxl
I get error
Traceback (most recent call last):
File "C:/Users/vik.makker/Desktop/NewProj/Internal Inventory Tracking System.py", line 1, in <module>
import openpyxl
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\__init__.py", line 5, in <module>
from openpyxl.workbook import Workbook
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\workbook\__init__.py", line 5, in <module>
from .workbook import Workbook
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\workbook\workbook.py", line 8, in <module>
from openpyxl.worksheet.worksheet import Worksheet
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\worksheet\worksheet.py", line 30, in <module>
from openpyxl.cell import Cell, MergedCell
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\cell\__init__.py", line 4, in <module>
from .cell import Cell, WriteOnlyCell, MergedCell
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\cell\cell.py", line 32, in <module>
from openpyxl.utils.datetime import (
File "C:\Users\vik.makker\Desktop\NewProj\openpyxl\utils\datetime.py", line 13, in <module>
from jdcal import (
ModuleNotFoundError: No module named 'jdcal'
The error is that although you've installed openpyxl, you haven't installed all of its dependencies (could be just a mistake in how the people that wrote openpyxl specified what packages their tool required). The last line of your error message says that you will also need to install jdcal, I suspect your code will work fine after that.

pygame: from pygame.locals import * not working

In my code
from pygame.locals import *
gets the following error message:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from pygame.locals import *
ImportError: No module named 'pygame.locals'
I have ensured that I don't have any files named pygame.py or pygame.pyc in my working directory and I'm using Python3.3.5 and pygame-1.9.2a0-hg on Windows 10. Could there be any other reason for this error?
Using Pycharm. My python file was called pygame. When I copied and pasted the code into another python file with a different name, it worked. This is as new to me as anything.

ImportError: No module named _grabscreen

I am new to python and using this tutorial http://code.tutsplus.com/tutorials/how-to-build-a-python-bot-that-can-play-web-games--active-11117 to build a bot which plays games.
I copy-pasted the file and installed the libraries .When i tried running the file in the terminal on my mac i got this error :
Traceback (most recent call last):
File "bot.py", line 2, in <module>
import Image, ImageGrab, ImageOps
File "/Library/Python/2.7/site-packages/PIL/ImageGrab.py", line 34, in <module>
import _grabscreen
ImportError: No module named _grabscreen
Here is the complete code
import os, sys
import Image, ImageGrab, ImageOps
import time, random
from random import randrange
import win32api, win32con
from numpy import *
I think you should pay attention to the these words in the tutorial, 'Some of the code and libraries are Windows-specific. There may be Mac or Linux equivalents, but we won't be covering them in this tutorial.'.
And current version of ImageGrag only works for windows.

Categories

Resources