컴퓨터/Python

python vscode pyqt5 snippet

풍경소리^^ 2022. 6. 9. 18:04

파일 - 기본 설정 - 사용자 코드 조각

{
	// Place your PyQt5_Excel 작업 영역 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 
	// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 
	// Placeholders with the same ids are connected.
	// Example:
	// "Print to console": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	"PyQt5": {
		"scope": "python",
		"prefix": "pyqt5",
		"body": [
			"import sys",
			"from PyQt5.QtWidgets import *",
			"",
			"class MyApp(QWidget):",
			"    def __init__(self):",
			"        super().__init__()",
			"        self.window_width, self.window_height = 700, 500",
			"        self.resize(self.window_width, self.window_height)",
			"        self.title = '$1'",
			"",
			"        self.InitUI()",
			"",
			"    def InitUI(self):",
			"        self.setWindowTitle(self.title)",
			"",
			"if __name__ == '__main__':",
			"    app = QApplication(sys.argv)",
			"    myApp = MyApp()",
			"    myApp.show()",
			"",
			"    try:",
			"        sys.exit(app.exec())",
			"    except SystemExit:",
			"        print('Closing Window...')"
		],
		"description": "Python PyQt5"
	}
}