TkMessageBox - No Module - python

import TkMessageBox
When I import TkMessageBox it displays the messsge 'ImportError: No module named 'TkMessageBox'.
As far as I know im using python 3.3.2 and Tk 8.5.
Am I using the wrong version of python or importing it wrong ?
Any answers would be extremely useful. Alternatively is there something similar in the version i am using?

In Python3.x things have changed a little bit:
>>> import tkinter
>>> import tkinter.messagebox
>>>
I mean what we call tkMessageBox in Python2.x becomes tkinter.messagebox in Python3.x

If you don't want to have to change the code for Python 2 vs Python 3, you can use import as:
try:
from tkinter import messagebox
except ImportError:
# Python 2
import tkMessageBox as messagebox
:edit:
However, tkinter is in a separate package in Debian due to Debian policies, so to avoid an incorrect fallback to Python 2 code I now use:
import sys
if sys.version_info.major >= 3:
from tkinter import messagebox
else:
import tkMessageBox as messagebox
Then using messagebox as follows will work in either version:
messagebox.showerror("Error", "Message.")

In Python 2.x, to import, you'd say import tkMessageBox. But in Python 3.x, it's been renamed to import tkinter.messagebox.
Hope it helped :))

for python 3.x
import tkinter
import tkinter.messagebox

from tkinter import messagebox sous Python 3
messagebox.showinfo(title=None, message=None, **options)

Related

Why does my tkinter app will show a node.js window?

I use pyinstaller to pack a .py file.
Then when I use something about web crawler (I use requests module).
This window will show and disappear fastly.
I want to say that it is maybe incredible.It wouldn't pop this window when I run this .py file,but after using pyinstaller to pack it,it will pop this window.
(In another computer,it doesn't install node.js.And it doesn't pop this window)
Here is the module I use:
from pynput import keyboard
from PIL import Image, ImageTk
import ctypes
from io import BytesIO
import threading
from win10toast import ToastNotifier
import base64
from win32com.shell import shell
import requests
import execjs
import sys
import pythoncom
import getpass
import tkinter
from random import randint
from tkinter import ttk
from tkinter import messagebox
import os
import json
import traceback
from webbrowser import open_new_tab
from tkinter import scrolledtext
import win32con, win32clipboard, win32gui
from PIL.ImageGrab import grabclipboard, grab
from aip import AipOcr
import time
And the window is this:
What should I do except uninstall node.js? How to avoid this node.js window shows?
Thanks in advance.
Thanks bro,acw1668's suggestion enlighten me a lot.
I want to say,execjs module will run js code.
And if your computer install node.js and you set PATH for node.js,Then your default js environment is node.js(If you don't install node.js,then your default js environment is Jscript in windows system).
So if you doesn't want to use node.js,you should set the default js environment in python.
# change the js environment.
os.environ["EXECJS_RUNTIME"] = "JScript"
# all of environment which execjs support
PyV8 = "PyV8"
Node = "Node"
JavaScriptCore = "JavaScriptCore"
SpiderMonkey = "SpiderMonkey"
JScript = "JScript"
PhantomJS = "PhantomJS"
SlimerJS = "SlimerJS"
Nashorn = "Nashorn"

PyQt4 not working on Spyder 3

I am trying to run a script with PyQt4 but Spyder gives an ModuleNotFoundError: No module named 'PyQt4' although it is installed. What am I doing wrong? I found a few threads in the net on this but I couldn't resolve the Problem.
Thanks in advance
Edit:
This is how I import it:
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
and this is where I got Spyder 3 (with Anaconda):
https://anaconda.org/anaconda/python

Import Error: No Module named 'Tkinter' [duplicate]

This question already has answers here:
ImportError: No module named 'Tkinter'
(27 answers)
Closed 5 years ago.
I am trying to create a simple gui and run in IDLE but every time I run it , it gives me the error :Import Error: No module named 'Tkinter'
This is my code if anybody is wondering:
from Tkinter import *
root = Tk()
root.mainloop()
I have also tried to verify if i have installed tkinter or not with command import tkinter and tkinter._test() and it shows that I have tkinter installed.
Use lowercase T for tkinter import statement for Python 3 :
import tkinter
IF your using python2 it's:
from Tkinter import *
But your using python3, so it's:
from tkinter import *

Windows Python 2.7 wxwidgets and 'gizmos'

Can anyone give me precise instructions on how to access the wx 'gizmos' module?
import wx.gizmos
ImportError: No module named gizmos
The code in question has this:
import wx
import string
import wx.gizmos
from wx.lib.mixins import treemixin
import Descriptor
'pip list' reports
wxPython-Phoenix (3.0.3.dev1830+0b5f910)
Do I have the right package installed? I should add that these files are present:
\python27\Lib\wxpython\wx-3.0-msw\wx\gizmos.py
\python27\Lib\wxpython\wx-3.0-msw\wx\_gizmos.pyd
[edit] For clarification, this seems to be OK so I'm reasonably sure the WX module is installed correctly.
import wx
import copy
# had to add .agw to get this to load
import wx.lib.agw.customtreectrl as CT
import DescriptorDetailsPanel
TAIA
Congrats, you have two installs of wx. You can use pkg_resources to get the one you want. Put the following at the top of the script:
__requires__ = ["wx >= 3.0"]
import pkg_resources
This will tell pkg_resources to set things up so that a version of wx of at least 3.0 will be available if you import wx rather than the default 2.x.
You can try to remove wxpython from pip install and reinstall wxpython from this site:
https://www.wxpython.org/download.php
It worked for me!

Python using Tkinter (Raspberry Pi running Debian).

To use Tkinter to open a dialog box I have the following Python 2.7 code:
from Tkinkter import Tk
from tkFileDialog import asksavesfinename
root = Tk().withdraw()
f = asksaveaskfilename()
This works just fine if I run the program under Idle.
However, if I run it, as root, from the LXTerminal, it fails with the exception “Client is not authorized to connect to Server…..”
Any help will be appreciated, Thanks.

Categories