为什么同样一段代码,vscode正常运行,终端里面就运行失败
Tofloor
poster avatar
Ligocut光剪视频剪辑软件
deepin
Backbone of ecological co-construction group
2019-08-21 08:00
Author

  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. import sys

  4. from PyQt5.QtCore import Qt
  5. from PyQt5.QtGui import QTextCharFormat, QBrush, QColor
  6. from PyQt5.QtWidgets import QApplication, QCalendarWidget


  7. StyleSheet = '''
  8. /*顶部导航区域*/
  9. #qt_calendar_navigationbar {
  10.     background-color: rgb(0, 188, 212);
  11.     min-height: 100px;
  12. }
  13. /*上一个月按钮和下一个月按钮(从源码里找到的objectName)*/
  14. #qt_calendar_prevmonth, #qt_calendar_nextmonth {
  15.     border: none; /*去掉边框*/
  16.     margin-top: 64px;
  17.     color: white;
  18.     min-width: 36px;
  19.     max-width: 36px;
  20.     min-height: 36px;
  21.     max-height: 36px;
  22.     border-radius: 18px; /*看来近似椭圆*/
  23.     font-weight: bold; /*字体加粗*/
  24.     qproperty-icon: none; /*去掉默认的方向键图片,当然也可以自定义*/
  25.     background-color: transparent;/*背景颜色透明*/
  26. }
  27. #qt_calendar_prevmonth {
  28.     qproperty-text: "<"; /*修改按钮的文字*/
  29. }
  30. #qt_calendar_nextmonth {
  31.     qproperty-text: ">";
  32. }
  33. #qt_calendar_prevmonth:hover, #qt_calendar_nextmonth:hover {
  34.     background-color: rgba(225, 225, 225, 100);
  35. }
  36. #qt_calendar_prevmonth:pressed, #qt_calendar_nextmonth:pressed {
  37.     background-color: rgba(235, 235, 235, 100);
  38. }
  39. /*年,月控件*/
  40. #qt_calendar_yearbutton, #qt_calendar_monthbutton {
  41.     color: white;
  42.     margin: 18px;
  43.     min-width: 60px;
  44.     border-radius: 30px;
  45. }
  46. #qt_calendar_yearbutton:hover, #qt_calendar_monthbutton:hover {
  47.     background-color: rgba(225, 225, 225, 100);
  48. }
  49. #qt_calendar_yearbutton:pressed, #qt_calendar_monthbutton:pressed {
  50.     background-color: rgba(235, 235, 235, 100);
  51. }
  52. /*年份输入框*/
  53. #qt_calendar_yearedit {
  54.     min-width: 50px;
  55.     color: white;
  56.     background: transparent;/*让输入框背景透明*/
  57. }
  58. #qt_calendar_yearedit::up-button { /*往上的按钮*/
  59.     width: 20px;
  60.     subcontrol-position: right;/*移动到右边*/
  61. }
  62. #qt_calendar_yearedit::down-button { /*往下的按钮*/
  63.     width: 20px;
  64.     subcontrol-position: left; /*移动到左边去*/
  65. }
  66. /*月份选择菜单*/
  67. CalendarWidget QToolButton QMenu {
  68.      background-color: white;
  69. }
  70. CalendarWidget QToolButton QMenu::item {
  71.     padding: 10px;
  72. }
  73. CalendarWidget QToolButton QMenu::item:selected:enabled {
  74.     background-color: rgb(230, 230, 230);
  75. }
  76. CalendarWidget QToolButton::menu-indicator {
  77.     /*image: none;去掉月份选择下面的小箭头*/
  78.     subcontrol-position: right center;/*右边居中*/
  79. }
  80. /*下方的日历表格*/
  81. #qt_calendar_calendarview {
  82.     outline: 0px;/*去掉选中后的虚线框*/
  83.     selection-background-color: rgb(0, 188, 212); /*选中背景颜色*/
  84. }
  85. '''


  86. class CalendarWidget(QCalendarWidget):

  87.     def __init__(self, *args, **kwargs):
  88.         super(CalendarWidget, self).__init__(*args, **kwargs)
  89.         # 隐藏左边的序号
  90.         self.setVerticalHeaderFormat(self.NoVerticalHeader)

  91.         # 修改周六周日颜色

  92.         fmtGreen = QTextCharFormat()
  93.         fmtGreen.setForeground(QBrush(Qt.green))
  94.         self.setWeekdayTextFormat(Qt.Saturday, fmtGreen)

  95.         fmtOrange = QTextCharFormat()
  96.         fmtOrange.setForeground(QBrush(QColor(252, 140, 28)))
  97.         self.setWeekdayTextFormat(Qt.Sunday, fmtOrange)


  98. if __name__ == "__main__":
  99.     app = QApplication(sys.argv)
  100.     app.setStyleSheet(StyleSheet)
  101.     w = CalendarWidget()
  102.     w.show()
  103. sys.exit(app.exec_())
Copy the Code
vscode正常运行
终端运行却是:

Reply Favorite View the author
All Replies
avatar
Feng Yu
deepin
2019-08-21 17:40
#1
我的直觉告诉我你的she-bang错了,she-bang必须放在第一行
Reply View the author
avatar
189******44
deepin
2019-08-21 18:19
#2
把第一行空行删掉
Reply View the author
avatar
Ligocut光剪视频剪辑软件
deepin
Backbone of ecological co-construction group
2019-08-22 07:04
#3
https://bbs.deepin.org/post/182067
把第一行空行删掉

真的可以诶,为什么前面多了一个空行就不行?
Reply View the author
avatar
Ligocut光剪视频剪辑软件
deepin
Backbone of ecological co-construction group
2019-08-22 07:05
#4
https://bbs.deepin.org/post/182067
我的直觉告诉我你的she-bang错了,she-bang必须放在第一行

she-bang?      
Reply View the author
avatar
Feng Yu
deepin
2019-08-22 07:42
#5

自行搜索这个重要的概念。这个是Linux/Unix脚本非常重要的概念,写错就会导致你的这个问题
Reply View the author
avatar
189******44
deepin
2019-08-22 19:36
#6
https://bbs.deepin.org/post/182067
真的可以诶,为什么前面多了一个空行就不行?

第一行是声明脚本解释器用的,以前不知道叫she-bang,感谢https://bbs.deepin.org/user/13508
Reply View the author
avatar
159******10
deepin
2019-08-22 21:39
#7
sys.path了解一下,ide会自动配置sys.path,将项目目录加进去,如果你从命令行执行,是不会有这个效果的,解决方法很简单,将项目所在目录加入到sys.path. 比如这样
  1. # 将项目目录加入到sys.path方便引入模块
  2. sys.path.append('/var/www')
Copy the Code
Reply View the author