我刚开始学习python,所以有些东西我不太懂。所以我尝试做一个小的桌面应用程序,我不想用一个代码来做所有的设计,所以我找到了像wxFormBuilder这样的东西,它非常适合我。问题是当我做了所有的窗口“设计”后,它在wxFormBuilder中看起来很好,但是当我复制PyCharm中的所有代码并启动程序时-一切都运行得很好,除了没有显示wxStaticText。我真的不明白问题出在哪里,因为我使用了Sizer和所有这些东西,甚至试图修改大多数与文本标签有关的代码,但仍然没有文本。我应用了PyCharm和wxFormBuilder的屏幕截图来显示它的外观。另外还有代码:
# -*- coding: utf-8 -*-
import wx
import wx.xrc
class MainWindow(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"FinanceC", pos=wx.DefaultPosition, size=wx.Size(700, 389),
style=wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
self.SetForegroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW))
self.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW))
fgSizer3 = wx.FlexGridSizer(2, 2, 0, 0)
fgSizer3.SetFlexibleDirection(wx.BOTH)
fgSizer3.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)
bSizer18 = wx.BoxSizer(wx.VERTICAL)
self.m_staticText1 = wx.StaticText(self, wx.ID_ANY,
u"Выберите html-файл экспортированных сообщений из телеграма",
wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText1.SetFont(
wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, "Century Gothic"))
bSizer18.Add(self.m_staticText1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, 20)
fgSizer5 = wx.FlexGridSizer(2, 2, 0, 0)
fgSizer5.SetFlexibleDirection(wx.BOTH)
fgSizer5.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)
bSizer32 = wx.BoxSizer(wx.VERTICAL)
self.html_path = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(540, -1), 0)
self.html_path.Enable(False)
bSizer32.Add(self.html_path, 0, wx.ALL, 5)
fgSizer5.Add(bSizer32, 1, wx.ALIGN_LEFT | wx.LEFT | wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.RIGHT | wx.TOP, 10)
bSizer311 = wx.BoxSizer(wx.VERTICAL)
self.button_html = wx.Button(self, wx.ID_ANY, u"Открыть", wx.DefaultPosition, wx.Size(105, -1), 0)
self.button_html.SetFont(
wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, "Century Gothic"))
bSizer311.Add(self.button_html, 0, 0, 5)
fgSizer5.Add(bSizer311, 1, wx.ALIGN_RIGHT | wx.BOTTOM | wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.RIGHT | wx.TOP, 15)
bSizer18.Add(fgSizer5, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.SHAPED, 5)
self.m_staticText11 = wx.StaticText(self, wx.ID_ANY, u"Укажите путь сохранения отчета",
wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText11.Wrap(-1)
self.m_staticText11.SetFont(
wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, "Century Gothic"))
bSizer18.Add(self.m_staticText11, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, 0)
fgSizer51 = wx.FlexGridSizer(2, 2, 0, 0)
fgSizer51.SetFlexibleDirection(wx.BOTH)
fgSizer51.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)
bSizer321 = wx.BoxSizer(wx.VERTICAL)
self.xlsx_path = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(540, -1), 0)
self.xlsx_path.Enable(False)
bSizer321.Add(self.xlsx_path, 0, wx.ALL, 5)
fgSizer51.Add(bSizer321, 1, wx.ALIGN_LEFT | wx.LEFT | wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.RIGHT | wx.TOP, 10)
bSizer3111 = wx.BoxSizer(wx.VERTICAL)
self.button_xlsx = wx.Button(self, wx.ID_ANY, u"Обзор", wx.DefaultPosition, wx.Size(105, -1), 0)
self.button_xlsx.SetFont(
wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, "Century Gothic"))
bSizer3111.Add(self.button_xlsx, 0, 0, 5)
fgSizer51.Add(bSizer3111, 1, wx.ALIGN_RIGHT | wx.BOTTOM | wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.RIGHT | wx.TOP,
15)
bSizer18.Add(fgSizer51, 1, wx.EXPAND, 5)
bSizer6 = wx.BoxSizer(wx.VERTICAL)
self.button_start = wx.Button(self, wx.ID_ANY, u"Начать", wx.DefaultPosition, wx.Size(100, 30), 0)
self.button_start.SetFont(
wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, "Century Gothic"))
bSizer6.Add(self.button_start, 0, wx.ALL, 5)
bSizer18.Add(bSizer6, 1, wx.ALIGN_CENTER_HORIZONTAL, 5)
bSizer7 = wx.BoxSizer(wx.VERTICAL)
self.text_convert = wx.StaticText(self, wx.ID_ANY, u"Конвертируем html-файл в таблицу xlsx...",
wx.DefaultPosition, wx.DefaultSize, 0)
self.text_convert.Wrap(-1)
self.text_convert.SetFont(
wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, "Century Gothic"))
bSizer7.Add(self.text_convert, 0, wx.ALL | wx.RESERVE_SPACE_EVEN_IF_HIDDEN, 5)
self.text_convert.Hide()
self.text_delete = wx.StaticText(self, wx.ID_ANY, u"Удаляем ненужные данные...", wx.DefaultPosition,
wx.DefaultSize, 0)
self.text_delete.Wrap(-1)
self.text_delete.SetFont(
wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, "Century Gothic"))
bSizer7.Add(self.text_delete, 0, wx.ALL | wx.RESERVE_SPACE_EVEN_IF_HIDDEN, 5)
bSizer18.Add(bSizer7, 1, wx.EXPAND | wx.RESERVE_SPACE_EVEN_IF_HIDDEN, 5)
self.text_delete.Hide()
bSizer71 = wx.BoxSizer(wx.VERTICAL)
self.text_calc = wx.StaticText(self, wx.ID_ANY, u"Производим расчеты...", wx.DefaultPosition, wx.DefaultSize, 0)
self.text_calc.Wrap(-1)
self.text_calc.SetFont(
wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, "Century Gothic"))
bSizer71.Add(self.text_calc, 0, wx.ALL | wx.RESERVE_SPACE_EVEN_IF_HIDDEN, 5)
self.text_calc.Hide()
self.m_staticText11111 = wx.StaticText(self, wx.ID_ANY,
u"Готово! Рабочий файл сохранен по указанному пути под именем \"",
wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText11111.Wrap(-1)
self.m_staticText11111.SetFont(
wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, "Century Gothic"))
bSizer71.Add(self.m_staticText11111, 0, wx.ALL | wx.RESERVE_SPACE_EVEN_IF_HIDDEN, 5)
bSizer18.Add(bSizer71, 1, wx.EXPAND | wx.RESERVE_SPACE_EVEN_IF_HIDDEN, 5)
fgSizer3.Add(bSizer18, 1, 0, 5)
self.m_staticText11111.Hide()
self.SetSizer(fgSizer3)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.button_html.Bind(wx.EVT_BUTTON, self.button_html_click)
self.button_xlsx.Bind(wx.EVT_BUTTON, self.button_xlsx_click)
self.button_start.Bind(wx.EVT_BUTTON, self.button_start_click)
def __del__(self):
pass
# Virtual event handlers, override them in your derived class
def button_html_click(self, event):
event.Skip()
def button_xlsx_click(self, event):
event.Skip()
def button_start_click(self, event):
event.Skip()
app = wx.App()
frame = MainWindow(None)
frame.Show()
app.MainLoop()
我试着在wxFormBuilder中创建一个只有文本的透明窗体,然后在PyCharm中打开它--它成功了。我还试着在我的主窗体中更改字体的样式、大小和不同的参数,试着在代码中编辑不同的参数,仍然没有任何结果。我还试着更改wxStaticText的位置和大小,它在PyCharm中发生了变化,当我这样做时,会有更多的空白(这个自由空间就在它必须在的地方),但仍然没有文本显示。也尝试了在文本中使用英语语言-仍然是一样的。了不起,我试过用wxTextCtrl替换wxStaticText,它成功了-文本显示出来了,但是元素不完全是我需要的。
1条答案
按热度按时间b4lqfgs41#
我已经弄清楚问题出在哪里了。文本的默认颜色是白色的,窗体的背景是白色的。在每个StaticText的代码中,你需要添加:
self.m_staticText1.SetForegroundColour('black')
所以它会出现。