Kivy屏幕过渡
这对我来说很难解释。
我正在研究一个自动生成电子邮件签名的项目。我制作了一个预先建造的“测试”版本来尝试自己。
它的目的是您放入电子邮件地址,并在您点击“生成签名”按钮后生成电子邮件签名。
问题是,当我在放置电子邮件地址后单击“生成签名”按钮时,它无济于事。我想要的是使用电子邮件签名进入下一个屏幕。
这是我在main.py文件中拥有的内容:
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.app import App
from kivy.uix.label import Label
from signature import *
class EmailSignatureGenerator(App):
"""Main app class"""
def build(self):
self.title = "Email Signature Generator"
return EmailScreen()
class SignatureScreen(GridLayout):
"""This is the screen that shows the signature. This also copies the signature to
the clipboard."""
def __init__(self, signature, **kwargs):
super().__init__(**kwargs)
self.cols = 1
Window.size = (500, 300)
self.add_widget(Label(text=str(signature)))
self.add_widget(Label(text="Your signature has been copied to your clipboard"))
self.add_widget(Label(text="Just go to Settings > Mail > Signature and paste!"))
class EmailScreen(GridLayout):
"""First screen that the user will see. It asks for the email address. The email
address is used to search for the user """
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.cols = 1
Window.size = (500, 300)
self.add_widget(Label(text="Email Address"))
self.email = TextInput(multiline=False)
self.email.focus = True
self.add_widget(self.email)
self.generate_signature = Button(text="Generate Signature")
self.generate_signature.bind(on_press=SignatureScreen)
self.add_widget(self.generate_signature)
if __name__ == "__main__":
EmailSignatureGenerator().run()
这是签名
from main import EmailScreen
class User:
"""External or internal employee"""
def __init__(self, full_name, job_title, phone, email):
self.full_name = full_name
self.job_title = job_title
self.phone = phone
self.email = email
class Office:
"""Office location of the corporate user"""
def __init__(self, name, address):
self.name = name
self.address = address
user = User("Matt Jarrett", "Deskside Technician", "(248)XXX-XXXX", EmailScreen().email)
office = Office("Main Corporate Office", "123 Main St. New York, NY 10000")
signature = f"{user.full_name} | {user.job_title} | {office.name}" \
f"{office.address} | {user.phone} | {user.email}"
。
This is kinda hard for me to explain.
I'm working on a project that automatically generates an email signature. I made a pre-built "test" version to try out myself.
The point of it is that you put in the email address and it generates an email signature after you hit the "Generate Signature" button.
The issue is that when I click the "Generate Signature" button after putting in the email address, it does nothing. What I want it to do is go to the next screen with the email signature.
Here is what I have in the main.py file:
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.app import App
from kivy.uix.label import Label
from signature import *
class EmailSignatureGenerator(App):
"""Main app class"""
def build(self):
self.title = "Email Signature Generator"
return EmailScreen()
class SignatureScreen(GridLayout):
"""This is the screen that shows the signature. This also copies the signature to
the clipboard."""
def __init__(self, signature, **kwargs):
super().__init__(**kwargs)
self.cols = 1
Window.size = (500, 300)
self.add_widget(Label(text=str(signature)))
self.add_widget(Label(text="Your signature has been copied to your clipboard"))
self.add_widget(Label(text="Just go to Settings > Mail > Signature and paste!"))
class EmailScreen(GridLayout):
"""First screen that the user will see. It asks for the email address. The email
address is used to search for the user """
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.cols = 1
Window.size = (500, 300)
self.add_widget(Label(text="Email Address"))
self.email = TextInput(multiline=False)
self.email.focus = True
self.add_widget(self.email)
self.generate_signature = Button(text="Generate Signature")
self.generate_signature.bind(on_press=SignatureScreen)
self.add_widget(self.generate_signature)
if __name__ == "__main__":
EmailSignatureGenerator().run()
And here is the signature.py
from main import EmailScreen
class User:
"""External or internal employee"""
def __init__(self, full_name, job_title, phone, email):
self.full_name = full_name
self.job_title = job_title
self.phone = phone
self.email = email
class Office:
"""Office location of the corporate user"""
def __init__(self, name, address):
self.name = name
self.address = address
user = User("Matt Jarrett", "Deskside Technician", "(248)XXX-XXXX", EmailScreen().email)
office = Office("Main Corporate Office", "123 Main St. New York, NY 10000")
signature = f"{user.full_name} | {user.job_title} | {office.name}" \
f"{office.address} | {user.phone} | {user.email}"
Thank you, any advice is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如评论中所述,您可以使用
screenmanager
。您要做的就是制作emailscreen
和signaturesCreen
从Kivyscreen
继承,然后将它们添加到您的应用程序中的ScreenManager中:这只是一个如何切换屏幕的示例。您可以将代码的任何其他功能添加到其中。
As said in the comments, you can use
ScreenManager
. All you have to do is makeEmailScreen
andSignatureScreen
inherit from a kivyScreen
and add them into a ScreenManager in your app:This is just an example of how to switch screens. You can add any other features of your code to it.