Tkinter按钮不正确尺寸/ X错误:坏Alloc

时间:2017-11-15 01:03:05

标签: python tkinter

我正在写一个Tkinter脚本,但是我遇到了一个错误。当我运行我的脚本时,我的所有按钮都非常小而且无法正常操作。例如,我的一个按钮应该打开文件对话框,而是返回错误代码:

X Error of failed request:  BadAlloc (insufficient resources for operation)
  Major opcode of failed request:  53 (X_CreatePixmap)
  Serial number of failed request:  4750
  Current serial number in output stream:  4769

然而,当我在Windows机器而不是我的Linux(Ubuntu)机器上运行我的代码时,它工作正常。
这是我的代码:

import qrtools
from Tkinter import *
from tkFileDialog import *
class Decode:
   def __init__(self,master):
       self.l = StringVar()
       self.master = master
       self.frame = Frame(self.master)
       self.browse = Button(master,text="Choose a File:", command = self.filenameget).pack()
       self.label = Label(master)
       self.label.pack()
       self.dcode = Button(master,text = "You Haven't Chosen A File Yet!")
       self.dcode.pack()
       self.dcodedata = Label(master)
       self.dcodedata.pack()
       self.quitbutt = Button(master, text = 'Back To Main Page',command = self.q).pack()
   def q(self):
       import subprocess
       subprocess.check_call(['python2.7','start.py'])
       quit()
   def filenameget(self):
       t = askopenfilename()
       print t
       self.label.config(text = t)
       self.dcode.config(text = 'Decode', command = self.get_decode)
   def get_decode(self):
       qr = qrtools.QR()
       qr.decode(str(self.label.cget("text")))
       self.dcodedata.config(text=str(qr.data))
def main():
   root = Tk()
   dc = Decode(root)
   root.title = "Qr Decoder By: Brian Ton"
   root.mainloop()
if __name__ == '__main__':
   main()

此外,我试图运行一个更简单的程序,但仍无济于事。
以下是简单程序的代码:

from Tkinter import *
master = Tk()
def print_test():
   print 'Hello'
button = Button(master, text = "Test Button", command = print_test)
button.pack()
mainloop()

我的主要问题是:

  • 这是Ubuntu问题吗?
  • 如果有,是否有解决方法?


如果你想查看一些截图,他们也会附上。

Ubuntu Qr Decoder
Windows Qr Decoder
Simple Program on Ubuntu
Simple Program on Windows

0 个答案:

没有答案