2

I have this error when run my python file: _tkinter.TclError: couldn't connect to display "127.0.0.1:0.0".

I mention that I am running VSCODE in WSL2 distro and Windows Pylance installed along with tkinter last version. In my ZSH terminal I have added this line as it is recommended by Microsoft for WSL2: export DISPLAY=$(grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}'):0.0. Commands like export DISPLAY=:0 doesn't work at all on WSL2.

Many thanks for any help, vhij

LE: I have Windows 11 with Ubuntu 20.04 LTS distro, Xming and VcXsrv.

car_bit
  • 21
  • 6

1 Answers1

0

I have solved now after many trials and combinations, but it works now:

$ nano ~/.zshrc

Copied this 2 lines:

export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0 export LIBGL_ALWAYS_INDIRECT=1

$ source ~/.zshrc

Then in Windows: open XLaunch: Multiple windows -> Start no client -> Check 'Disable access control' -> Finish.

After that, I went on Windows Defender Firewall with Advanced Security and made 'green' status to all of VcXsrv and Xming X Server in Inbound Rules: Properties -> Allow the connection -> OK. (I have tried to add in Scope -> Remote IP address -> These IP addressess -> 172.72.0.1, but it didn't worked).

enter image description here

enter image description here

Then I run the python script successfully and tkinter window pop-up.

car_bit
  • 21
  • 6