Reputation: 155
I am trying to use Tkinter in Python for data visualization. The code here:
import fdb
from tkinter import *
from PIL import ImageTk, Image
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import sys
import os
if os.environ.get('DISPLAY','') == '':
print('no display found. Using :0.0')
os.environ.__setitem__('DISPLAY', ':0.0')
root = Tk()
def graph():
plt.hist(total_orders, months)
plt.show()
root.mainloop()
However, i got this error:
_tkinter.TclError: no display name and no $DISPLAY environment variable
After that, I researched and found some solutions for this error. I tried some of them:
1- I added matplotlib.use('Agg')
and doesn't work, I got the same error.
2- I added if os.environ.get('DISPLAY','') == '': print('no display found. Using :0.0') os.environ.__setitem__('DISPLAY', ':0.0')
it doesn't work either and i got this error:
_tkinter.TclError: couldn't connect to display ":0.0"
I tried to use xhost but even i installed sudo apt-get install x11-xserver-utils
xhost run as xhost: unable to open display ""
.
How can i solve this problem?
Upvotes: 3
Views: 5117
Reputation: 147
Seeing that your DISPLAY variable is not set, it looks like you are running the program without a connected display. If you are connected via SSH, try using the -X or -Y flags.
Example: ssh -X 10.0.1.59
or ssh -Y 10.0.1.59
Upvotes: 2