[Tkinter] askdirectory path seperator is / instead of \ ?

Post here if you need help with creating a Graphical User Interface in Python.

[Tkinter] askdirectory path seperator is / instead of \ ?

Postby vishwas » Sun Jul 21, 2013 4:49 am

hello evry1 i was facing some kind of different output error ....for simplicity i am providing you the code and the kind of error i am facing and please give the valuvable solution and full answer with explanation ....so tat other user can get help from IT....... :ugeek:
Code: Select all
from Tkinter import *
from tkFileDialog import askdirectory

root = Tk()


## use a Tkinter.StringVar with and Tkinter Entry widget
d1 = StringVar()
e1 = Entry(root, textvariable=d1)
e1.pack()

def browser():
   dir1 = askdirectory()
   print dir1
   if dir1:
     d1.set(dir1)

b1 = Button(root, text="Browse", command=browser)
b1.pack()

root.mainloop()



AND the output is D:/vishwas/RESOURCE......here the slash portion between the strings is like / / / but by the address path way it should be like \ \ \ ryt ??? :? like this D:\vishwas\RESOURCE......help :roll:
Last edited by Yoriz on Mon Jul 22, 2013 4:42 pm, edited 1 time in total.
Reason: changed title moved to GUI part of the forum
vishwas
 
Posts: 14
Joined: Thu Mar 14, 2013 9:57 am

Re: giving wrong output by the askdirectory code in python

Postby micseydel » Sun Jul 21, 2013 4:52 am

Do you get a traceback?
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1222
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: giving wrong output by the askdirectory code in python

Postby vishwas » Mon Jul 22, 2013 5:06 am

traceback ???? i think its use for exception ryt.....no able to understand wat you have asked ...but just copy and paste the script in your IDLE and you will get to know what i am saying ..... :mrgreen:
vishwas
 
Posts: 14
Joined: Thu Mar 14, 2013 9:57 am

Re: giving wrong output by the askdirectory code in python

Postby metulburr » Mon Jul 22, 2013 8:55 am

Code: Select all
from Tkinter import *
from tkFileDialog import askdirectory
import os

root = Tk()


## use a Tkinter.StringVar with and Tkinter Entry widget
d1 = StringVar()
e1 = Entry(root, textvariable=d1)
e1.pack()

def browser():
    dir1 = askdirectory()
    print os.listdir(dir1) #path works
    if dir1:
        replacer = dir1.replace('/', '\\')
        d1.set(replacer)
        print 'recieved {} but switched to {}'.format(dir1, replacer)

b1 = Button(root, text="Browse", command=browser)
b1.pack()

root.mainloop()


In Windows, you can you \ or /, for file sep, its probably auto set to do / to be compatable with linux, mac. Its not going to affect the outcome, as seen above os.listdir('.') has no problem using the path's with /. So all you mean is to just to display it as using \? In that case just replace one for the other on output, as shown above.

and regarding your star imports, check here
viewtopic.php?f=25&t=4822
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1387
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: [Tkinter] askdirectory path seperator is / instead of \

Postby vishwas » Tue Jul 23, 2013 4:29 am

Thanks a lot......man really.....thank you..... :D
vishwas
 
Posts: 14
Joined: Thu Mar 14, 2013 9:57 am


Return to GUI

Who is online

Users browsing this forum: No registered users and 1 guest