tkinter学习07

解决ubuntu系统 上没有tkinter模块的问题

rico@rico-VirtualBox:~/桌面$ python3 canves
Traceback (most recent call last):
  File "canves", line 3, in <module>
    import tkinter as tk
ModuleNotFoundError: No module named 'tkinter'
rico@rico-VirtualBox:~/桌面$ sudo apt-get install python3-tk
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会同时安装下列软件:
  blt libtcl8.6 libtk8.6 tk8.6-blt2.5
建议安装:
  blt-demo tcl8.6 tk8.6 tix python3-tk-dbg
下列【新】软件包将被安装:
  blt libtcl8.6 libtk8.6 python3-tk tk8.6-blt2.5
升级了 0 个软件包,新安装了 5 个软件包,要卸载 0 个软件包,有 239 个软件包未被升级。
需要下载 2,252 kB 的归档。
解压缩后会消耗 9,231 kB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libtcl8.6 amd64 8.6.8+dfsg-3 [881 kB]

 已安装成功。

#!/usr/bin/python3

import tkinter as tk

window=tk.Tk()
window.title("my window")
window.geometry("200x200")

canvas = tk.Canvas(window, bg='blue', height=100, width=200)
canvas.pack()
image_file = tk.PhotoImage(file='ins.gif')
image = canvas.create_image(10, 10, anchor='nw', image=image_file)
x0, y0, x1, y1= 50, 50, 80, 80
line = canvas.create_line(x0, y0, x1, y1)
oval = canvas.create_oval(x0, y0, x1, y1, fill='red')  #创建一个圆,填充色为`red`红色
arc = canvas.create_arc(x0+30, y0+30, x1+30, y1+30, start=0, extent=180)  #创建一个扇形
rect = canvas.create_rectangle(100, 30, 100+20, 30+20)   #创建一个矩形
def moveit():
    canvas.move(rect, 0, 2)
b=tk.Button(window,text="move",command=moveit).pack()


window.mainloop()



猜你喜欢

转载自www.cnblogs.com/Mengchangxin/p/9900321.html