我正在Tkinter中编写一个应用程序,我正在创建一个ctrl + s保存功能,我想在菜单中显示,但我无法将实际文本“Ctrl + S”右对齐命令。我尝试使用选项卡,如下例所示,但这不起作用,我找不到任何内容。这是我试过的:
class TestAccount(models.Model):
decimal = models.DecimalField(max_digits=5, decimal_places=2)
integer = models.IntegerField()
In [1]: ta = TestAccount()
In [2]: ta.integer = 1
In [3]: ta.decimal = 1
In [4]: ta.save()
In [5]:
In [5]:
In [5]: ta
Out[5]: <TestAccount: TestAccount object>
In [6]: ta.id
Out[6]: 1L
In [7]: from django.db.models.expressions import F
In [8]: ta = TestAccount.objects.get(id=1)
In [9]: ta.integer = F('integer') + 1
In [10]: ta.save()
---------------------------------------------------------------------------
ValidationError Traceback (most recent call last)
<ipython-input-10-6e9eda341b34> in <module>()
----> 1 ta.save()
/usr/lib/python2.7/site-packages/django/db/models/base.pyc in save(self, force_insert, force_update, using, update_fields)
706
707 self.save_base(using=using, force_insert=force_insert,
--> 708 force_update=force_update, update_fields=update_fields)
709 save.alters_data = True
710
/usr/lib/python2.7/site-packages/django/db/models/base.pyc in save_base(self, raw, force_insert, force_update, using, update_fields)
730 if not meta.auto_created:
731 signals.pre_save.send(sender=origin, instance=self, raw=raw, using=using,
--> 732 update_fields=update_fields)
733 with transaction.atomic(using=using, savepoint=False):
734 if not raw:
/usr/lib/python2.7/site-packages/django/dispatch/dispatcher.pyc in send(self, sender, **named)
190
191 for receiver in self._live_receivers(sender):
--> 192 response = receiver(signal=self, sender=sender, **named)
193 responses.append((receiver, response))
194 return responses
/media/sf_helium/build/helium/internal/signals.pyc in validate_model(sender, **kwargs)
12 def validate_model(sender, **kwargs):
13 if 'raw' in kwargs and not kwargs['raw']:
---> 14 kwargs['instance'].full_clean()
15
16 @receiver(pre_delete)
/usr/lib/python2.7/site-packages/django/db/models/base.pyc in full_clean(self, exclude, validate_unique)
1142
1143 if errors:
-> 1144 raise ValidationError(errors)
1145
1146 def clean_fields(self, exclude=None):
ValidationError: {'integer': [u"'F(integer) + Value(1)' value must be an integer."]}
而且我不确定如何控制间距和对齐方式。谢谢。
答案 0 :(得分:3)
菜单项具有专门用于此目的的accelerator
属性:
加速器指定要在菜单项右侧显示的字符串。通常描述一个加速键击序列 可以键入以调用与菜单条目相同的功能。这个 选项不适用于分隔符或撕下条目。
self.file_menu.add_command(..., accelerator="Ctrl+S")