Python tkinter 不会显示对角线 [英] Python tkinter wont display diagonal lines

查看:27
本文介绍了Python tkinter 不会显示对角线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用 Arch Linux,将一个 python 文件从我的 mac 传输到 Linux 并运行它后,它不起作用.这很常见,但是,它不起作用的方式非常奇怪.该程序是绘制线方程的程序,但在 Linux 上,tkinter Canvas 对象的 create_line 方法不再显示对角线.例如,绘制 y=x 不会显示任何内容,但它会说它成功绘制了线条.我尝试在我的程序之外画一条对角线(从 (0, 0) 到 (20, 20)),但它在那里也不起作用.我尝试调整宽度,但没有任何改变.我正在使用 i3wm,并尝试了 lxde,它没有改变任何东西.我用pacman安装了最新版本的python3,我不得不单独安装tk.有什么办法可以解决这个问题吗?

I recently started using Arch Linux, and after transferring a python file from my mac to the Linux, and running it, it did not work. This is pretty common, but, the way in which it didn't work was very strange. The program is one that graphs equations of lines, but on Linux, the tkinter Canvas object's create_line method no longer displays diagonal lines. For example, graphing y=x wouldn't show anything but it would say it successfully graphed the line. I tried drawing a diagonal line (from (0, 0) to (20, 20)) outside of my program, and it doesn't work there either. I tried adjusting the width, which didn't change anything. I'm using i3wm, and tried lxde, which didn't change anything. I have the latest version of python3 installed with pacman, and I had to install tk separately. Is there any way to fix this?

更新:它也不适用于从网站安装的 python3

Update: It doesn't work with python3 installed from the website either

更新:在运行arch linux的虚拟机中工作,所以可能与驱动程序或硬件有关

Update: Works in a virtual machine running arch linux, so it may have something to do with the drivers or hardware

这是一个例子

from tkinter import *
root = Tk()
canvas = Canvas(master=root)
canvas.pack()
canvas.create_line(0, 0, 20, 20)

返回 1,不执行任何其他操作.同时:

returns 1, doesn't do anything else. Meanwhile:

canvas.create_line(0, 20, 20, 20) # horizontal line

返回 1、2、3...(取决于你画了多少东西)并画线.

returns 1, 2, 3... (depends on how many things you have drawn) and draws the line.

推荐答案

我能够通过安装正确的驱动程序来修复它,在我的例子中是 xf86-video-intel,然后重新启动.我认为这只是一个新手错误,但是缺少驱动程序只影响 tkinter 中的对角线仍然有点有趣.

I was able to fix it by installing the correct driver, in my case xf86-video-intel, and rebooting. I think it was just a newbie mistake, but its still sort of interesting that the missing driver only affected diagonal lines in tkinter.

这篇关于Python tkinter 不会显示对角线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆