简体   繁体   English

如何从终端打开带有相应应用程序的文件?

[英]how to open a file with corresponding application from terminal?

I am new to linux, so would be great if anyone could help me on this! 我是linux的新手,所以如果有人可以在这方面帮助我,那就太好了!

I want to open a file, say a text file using text editor from terminal. 我想打开一个文件,例如从终端使用文本编辑器打开一个文本文件。 The thing is i dont want to just view/edit the file. 事情是我不想只是查看/编辑文件。 I know i could do this using cat or vi. 我知道我可以用cat或vi做到这一点。 But i wanted to open something by its corresponding application and I wanted to do this from terminal. 但是我想通过其相应的应用程序打开某些内容,而我想从终端上进行操作。 Is it possible? 可能吗?

I actually wanted to open the file from a gui i am building. 我实际上想从我正在构建的GUI中打开文件。 I am building my gui using tkinter python. 我正在使用tkinter python构建我的GUI。

So i am looking for a command to open the file so that i could use it in my subprocess command. 因此,我正在寻找一个打开文件的命令,以便可以在子进程命令中使用它。

A repeat of an earlier question, but it's hard to search for if you don't know about the "start" command in windows or "open" on OSX. 重复先前的问题,但是如果您不知道Windows中的“开始”命令或OSX中的“打开”命令,则很难进行搜索。 xdg-open is the Linux desktop equivalent. xdg-open与Linux桌面等效。

https://superuser.com/questions/38984/linux-equivalent-command-for-open-command-on-mac-windows https://superuser.com/questions/38984/linux-equivalent-command-for-open-command-on-mac-windows

[Edit] I'm taking the requirement to mean "command picture.jpg" should open in your image viewer, "command song.mp3" should open in the users music player etc. Open from the terminal, not literally in the terminal... If command == xdg-open, it should work. [编辑]我走的意思“命令picture.jpg”应该在你的图像查看器中打开“命令Song.mp3的”应该在用户的音乐播放器等终端打开终端,不能随便打开的要求。 ..如果命令== xdg-open,它应该可以工作。

Refer here Opening File (Tkinter) 请参阅此处打开文件(Tkinter)

In GUI programming, think of the GUI as a tree or a graph. 在GUI编程中,请将GUI视为树或图形。 The root is your main GUI window, and within it contains different elements (Labels, Buttons, Images, TextBoxes, etc.), which are your children to your tree. 根是您的GUI主窗口,其中包含不同的元素(标签,按钮,图像,文本框等),它们是树的子级。

In order to use tkinter in python: 为了在python中使用tkinter:

import tkinter as tk
root = tk.Tk()

A window pops up. 弹出一个窗口。 that is your root GUI window with nothing in it. 那是您的根GUI窗口,其中没有任何内容。 If you close this window, the root GUI object will be destroyed. 如果关闭此窗口,则根GUI对象将被破坏。

You can use similar approach for your GUI. 您可以对GUI使用类似的方法。 See more here http://www.python-course.eu/tkinter_labels.php 在此处查看更多信息http://www.python-course.eu/tkinter_labels.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM