【问题标题】:Segmentation fault with Tkinter?Tkinter 的分段错误?
【发布时间】:2017-12-22 13:44:22
【问题描述】:

所以,我有这个功能应该让用户选择几个图像文件以包含在文档中。出于某种原因,每次我在 Mac OSX 10.11.6 上的较大程序中运行此函数时都会崩溃,并且出现分段错误错误,特别是分段错误 11。然而,当我单独运行该函数时,它工作得很好.这是怎么回事?

import sys
import logging
from time import strftime
import Tkinter as Tk
import tkFileDialog

def get_filepaths(title=None):
    """
    Gets an unlimited number of filepaths until the user clicks 'Cancel'.
    :param title: The title of the window dialog.
    :return: list of filepaths
    """
    if title is None:
        title = "Select an image to add to the report. Click Done to load " \
                "the file. When you're finished, click Cancel to continue."

    logging.debug("Inputting filepaths...")
    types = (("all files", "*.*"), ("images", "*.jpg *.jpeg *.png *.tiff "
                                              "*.tif *.gif *.bmp *.psd"))
    root = Tk.Tk()
    root.withdraw()
    paths = []
    while True:
        path = tkFileDialog.askopenfilename(title=title, filetypes=types)
        if len(path) == 0:
            break
        paths.append(path)
    return paths

【问题讨论】:

  • 您是否正在创建多个Tk.Tk 实例?一个 tkinter 程序应该有 一个 Tk 类的实例。
  • @Rawing 不,你在sn-p中看到的Tk.Tk是它在整个程序中唯一出现的地方。
  • @Novel 是的,我安装了一个新版本的 ActiveTCL 用于我的 virtualenv。当我在命令行上执行tclsh 后跟info patchlevel 时,它说我的版本是8.6.6。

标签: python python-2.7 tkinter segmentation-fault tk


【解决方案1】:

我在橙色 pi 上的 debian Jessie armhf 和氚板上的 Ubuntu 焦点 armhf 上遇到过这个问题。 (allwinner H3 cpu,橙色 pi 的克隆)。 2021年问题依然存在。Opensuseleap 42.1,X86_64上没有问题

我发现这条评论是关于对 Tix 库文件 Utils.tcl 进行简单的 kludge 修复,这解决了我的代码中的问题。它绕过了 tixBusy 函数。

bugs.archlinux.org/task/33607

【讨论】:

  • 你能发布你迄今为止尝试过的解决方案吗?
猜你喜欢
  • 1970-01-01
  • 2021-11-01
  • 1970-01-01
  • 2014-11-17
  • 1970-01-01
  • 2018-11-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多