ผมไม่สามารถใช้ module tkinter ได้ครับ

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น ภาษา Java ภาษา Python

Moderators: mindphp, ผู้ดูแลกระดาน

benzas00123
PHP Super Member
PHP Super Member
Posts: 244
Joined: 06/01/2020 9:58 am

ผมไม่สามารถใช้ module tkinter ได้ครับ

Post by benzas00123 » 29/01/2020 2:04 pm

ผมลองสร้าง Gui แบบ basic ให้โชวน์ แค่ตัวกรอบ แต่ไม่สามารถ run ได้ มันขึ้น error ครับ

Code: Select all

from tkinter import *

root = Tk ()

root.mainloop ()

error

Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in <module>
import _tkinter
ModuleNotFoundError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/com003/Desktop/Ben/Optimize_picture/guimain.py", line 1, in <module>
from tkinter import *
File "/usr/lib/python3.6/tkinter/__init__.py", line 39, in <module>
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in <module>
import _tkinter
ModuleNotFoundError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/com003/Desktop/Ben/Optimize_picture/guimain.py", line 1, in <module>
from tkinter import *
File "/usr/lib/python3.6/tkinter/__init__.py", line 39, in <module>
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package

User avatar
chatee supasand
PHP VIP Members
PHP VIP Members
Posts: 1663
Joined: 04/06/2019 10:06 am

Re: ผมไม่สามารถใช้ module tkinter ได้ครับ

Post by chatee supasand » 29/01/2020 2:21 pm

pip install module รึยังอะ
Image

benzas00123
PHP Super Member
PHP Super Member
Posts: 244
Joined: 06/01/2020 9:58 am

Re: ผมไม่สามารถใช้ module tkinter ได้ครับ

Post by benzas00123 » 29/01/2020 2:26 pm

chatee supasand wrote:
29/01/2020 2:21 pm
pip install module รึยังอะ
ที่ลองมา มี 4 ตัวนี้ครับ

sudo apt-get install python3-tkinter
sudo apt-get install python3-Tkinter
pip3 install Tkinter
pip3 install tkinter

benzas00123
PHP Super Member
PHP Super Member
Posts: 244
Joined: 06/01/2020 9:58 am

Re: ผมไม่สามารถใช้ module tkinter ได้ครับ

Post by benzas00123 » 29/01/2020 2:40 pm

ใช้ pycharm python 3.6 ใน os ubuntu 14.04 ครับ

User avatar
chatee supasand
PHP VIP Members
PHP VIP Members
Posts: 1663
Joined: 04/06/2019 10:06 am

Re: ผมไม่สามารถใช้ module tkinter ได้ครับ

Post by chatee supasand » 29/01/2020 2:40 pm

ลองโค้ดนี้ดูได้ไหม

Code: Select all

import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red",
                              command=self.master.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        print("hi there, everyone!")

root = tk.Tk()
app = Application(master=root)
app.mainloop()
Image

benzas00123
PHP Super Member
PHP Super Member
Posts: 244
Joined: 06/01/2020 9:58 am

Re: ผมไม่สามารถใช้ module tkinter ได้ครับ

Post by benzas00123 » 29/01/2020 2:41 pm

chatee supasand wrote:
29/01/2020 2:40 pm
ลองโค้ดนี้ดูได้ไหม

Code: Select all

import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red",
                              command=self.master.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        print("hi there, everyone!")

root = tk.Tk()
app = Application(master=root)
app.mainloop()
ไม่ได้ครับ

error

Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in <module>
import _tkinter
ModuleNotFoundError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/com003/Desktop/Ben/Optimize_picture/guimain.py", line 1, in <module>
import tkinter as tk
File "/usr/lib/python3.6/tkinter/__init__.py", line 39, in <module>
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in <module>
import _tkinter
ModuleNotFoundError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/com003/Desktop/Ben/Optimize_picture/guimain.py", line 1, in <module>
import tkinter as tk
File "/usr/lib/python3.6/tkinter/__init__.py", line 39, in <module>
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package

benzas00123
PHP Super Member
PHP Super Member
Posts: 244
Joined: 06/01/2020 9:58 am

Re: ผมไม่สามารถใช้ module tkinter ได้ครับ

Post by benzas00123 » 29/01/2020 3:30 pm

error ตอนติดตั้งครับ

Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'python3-tk' instead of 'python3.6-tk'
The following packages were automatically installed and are no longer required:
libbit-vector-perl libcarp-clan-perl libclass-data-inheritable-perl
libclass-method-modifiers-perl libcrypt-openssl-bignum-perl
libcrypt-openssl-rsa-perl libdata-random-perl libdate-calc-perl
libdate-calc-xs-perl libgd-perl libgnome2-gconf-perl libgsm1:i386
libgstreamer-plugins-base1.0-0:i386 libgstreamer1.0-0:i386 libmouse-perl
libnet-dropbox-api-perl libnet-oauth-perl libpcap0.8:i386
libpython3.6-minimal libpython3.6-stdlib pycharm-data python3-colorama
python3-distlib python3-html5lib python3-wheel python3.6-minimal wine-stable
wine-stable-amd64 wine-stable-i386:i386
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
blt
Suggested packages:
blt-demo tix python3-tk-dbg
The following packages will be REMOVED:
python-tk
The following NEW packages will be installed:
blt python3-tk
0 upgraded, 2 newly installed, 1 to remove and 189 not upgraded.
Need to get 55.9 kB of archives.
After this operation, 175 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
WARNING: The following packages cannot be authenticated!
blt python3-tk
Install these packages without verification? [y/N] y
Err http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu/ trusty/main blt amd64 2.5.3+dfsg-3~14.04.york1
403 Forbidden [IP: 91.189.95.83 80]
Err http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu/ trusty/main python3-tk amd64 3.6.3-0ubuntu1~14.04.york0
403 Forbidden [IP: 91.189.95.83 80]
E: Failed to fetch http://ppa.launchpad.net/jonathonf/pyth ... _amd64.deb 403 Forbidden [IP: 91.189.95.83 80]

E: Failed to fetch http://ppa.launchpad.net/jonathonf/pyth ... _amd64.deb 403 Forbidden [IP: 91.189.95.83 80]

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

User avatar
jirawoot
PHP VIP Members
PHP VIP Members
Posts: 1985
Joined: 17/06/2019 10:30 am

Re: ผมไม่สามารถใช้ module tkinter ได้ครับ

Post by jirawoot » 29/01/2020 3:33 pm

apt-get update

Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “Programming - C/C++ & java & Python”

Who is online

Users browsing this forum: No registered users and 25 guests