“ImportError: No module named tkinter” when using Pmw

后端 未结 5 802
傲寒
傲寒 2020-12-20 21:13

Here\'s my problem: I\'m running the code in this example. I have Python 2.7 and 3 installed on my RaspberryPi but I have checked and double-checked, and I am running the c

相关标签:
5条回答
  • 2020-12-20 21:33

    rewritten script that runs on python 3.4.0 onwards

    def add():
            print ("Enter the two numbers to Add")
            A=int(input("Enter A: "))
            B=int(input("Enter B: "))
            return A + B 
    
    def sub():
            print ("Enter the two numbers to Subtract")
            A=int(input("Enter A: "))
            B=int(input("Enter B: "))
            return A - B
    
    def mul():
            print ("Enter the two numbers to Multiply")
            A=int(input("Enter A: "))
            B=int(input("Enter B: "))
            return A * B
    
    def div():
            print ("Enter the two number to Divide")
            A=float(input("Enter A: "))
            B=float(input("Enter B: "))
            return A / B
    
    print ("1: ADDITION")
    print ("2: SUBTRACTION")
    print ("3: MULTIPLICATION")
    print ("4: DIVISION")
    print ("0: QUIT")
    
    while True:
    
        CHOICE = int(input("ENTER THE CORRESPONDING NUMBER FOR CALCULATION ")) 
    
        if CHOICE == 1: 
            print ('ADDING TWO NUMBERS:')
            print (add())
    
        elif CHOICE == 2:
            print ('SUBTRACTING TWO NUMBERS')
            print (sub())
    
        elif CHOICE == 3:
            print ('MULTIPLYING TWO NUMBERS')
            print (mul())
    
        elif CHOICE == 4:
            print ("DIVIDEING TWO NUMBERS")
            print (div())
    
        elif CHOICE == 0:
            exit()
        else:
            print ("The value Enter value from 1-4")
    
    0 讨论(0)
  • 2020-12-20 21:37

    you have imported wrong module use: import Tkinter

    0 讨论(0)
  • 2020-12-20 21:42

    Another workaround would be the following:

    try:
        import tkinter
    except:
        import Tkinter as tkinter
    

    This way you would always have the module tkinter available and depending on the Python version your program loads tkinter or Tkinter.

    0 讨论(0)
  • 2020-12-20 21:43

    I was facing the same problem with matplotlib.pyplot (python 2.7+) in my CentOs. I solved the problem by just installing the tkinter. sudo yum install tkinter. Hope this can help you.

    0 讨论(0)
  • 2020-12-20 21:51

    Maybe I can help you on how to remove the error.

    here are two thoughts:

    1) you use python 2.xx and have installed the python 3 pwm module (Tkinter was renamed to tkinter from Python 2 to 3)

    2) you do the following before the import and hope it helps:

    #import tkinter
    #Traceback (most recent call last):
    #  File "<pyshell#11>", line 1, in <module>
    #    import tkinter
    #ImportError: No module named tkinter
    
    import sys, Tkinter
    sys.modules['tkinter'] = Tkinter # put the module where python looks first for modules
    #import tkinter # now works!
    
    0 讨论(0)
提交回复
热议问题