'button shape and text alignment changed after updating
I have recently deleted and re-installed python, kivy, kivymd. Then, my kivy button's shape changed. My MDRaisedButton used to have slightly rounded corners but now it is very sharp. Also, My MDRectangleFlatIconButton had icon and text aligned in the center but now it is located on the left side. I can't move icon and text in the center of the button.
Has there been any update among kivy or kivymd recently? I can't fix my problem now.
My python version has been 3.10.4 always. but i think Kivymd could have been updated.
Would you help me to put icon and text in the center of MDRectangleFlatIconButton? Is it possible to modify MDRaisedButton with rounded corners?I appreciate your help.
Pip freeze:
My old looks: icon and text centered
New look: on left side. i can't locate them in the center
.py code '''
from kivy.uix.widget import Widget
'''Setting the size of first window for program'''
from kivy.config import Config #another way of setting size of window
Config.set('graphics', 'width', '600') # from kivy.core.window import Window
Config.set('graphics', 'height', '750') # Window.size = ("600", "750")
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.uix.popup import Popup
from kivy.properties import StringProperty
Builder.load_file('new_window_popup.kv')
class Dex(Popup):
pass
class Remi(Popup):
pass
class Info(Popup):
bt_information = StringProperty('')
def on_update(self):
self.bt_information = "Young"
pass
class MyLayout(Widget):
pass
from kivy.core.text import Label as CLabel
from kivy.clock import Clock
class AwesomeApp(MDApp):
def build(self):
self.title = "My house"
# Clock.schedule_interval(self.change_text, 2)
return MyLayout()
def change_text(self, *args):
butt = self.root.ids.bt_information # this is the MDRectangleFlatIconButton
label = butt.ids.lbl_txt # this is the MDLabel of concern
#butt.text += ' qwe' # change the text of the Label
# calculate the required width
core_label = CLabel(text=label.text, font_name=label.font_name, font_size=label.font_size, max_lines=1)
core_label.refresh()
# set the width of the label to hold the new text on one line
label.width = core_label.width
if __name__ == '__main__':
AwesomeApp().run()
'''
new_window_popup.kv file
'''
#:import Factory kivy.factory.Factory
#:import MDRaisedButton kivymd.uix.button
<Dex>:
auto_dismiss: False
size_hint: 1, 1
title: "Weight-Based Dose Calculator "
canvas.before:
Color:
rgba: (0,1,0,1)
Rectangle:
pos:self.pos
size:self.size
BoxLayout:
orientation: "vertical"
size:root.width, root.height
Label:
text: "Dex 1"
Button:
text: "Close"
font_size: 24
on_release: root.dismiss()
<Remi>:
auto_dismiss: False
size_hint: 1, 1
title: "Weight-Based Dose Calculator "
canvas.before:
Color:
rgba: (0,1,0,1)
Rectangle:
pos:self.pos
size:self.size
BoxLayout:
orientation: "vertical"
size:root.width, root.height
Label:
text: "Remi"
Button:
text: "Close"
font_size: 24
on_release: root.dismiss()
<Info>:
appName:appName
auto_dismiss: False
size_hint: 1, 1
title: "Change Info"
canvas.before:
Color:
rgba: (0,1,0,1)
Rectangle:
pos:self.pos
size:self.size
BoxLayout:
orientation: "vertical"
size:root.width, root.height
Label:
text: "What is your App name?"
BoxLayout:
orientation: "horizontal"
MDTextField:
id: appName
hint_text: "App Name"
color_mode: 'primary'
current_hint_text_color: 1,1,1,1
hint_text_color_focus: 1,1,1,.9
line_color_focus: 1,1,1,1
font_size: '25sp'
text_color_normal: 1,1,1,.9
text_color_focus: 0,0,1,.9
focus: True
write_tab: False
Button:
text: "Update Top Bar\'s name"
font_size: 24
size_hint: .8, .2
# on_release: root.updateName()
on_release:
app.title = appName.text
#root.on_update()
app.root.ids.bt_information.text = appName.text
#app.change_text()
# app.root.ids.bt_information.text_size = self.size
Button:
text: "Close"
font_size: 24
on_release: root.dismiss()
<MyLayout>
MDBoxLayout:
orientation:"vertical"
size: root.width, root.height
MDRaisedButton:
text: "Dex"
font_size: 32
text_color: 0,0,0,.9
size_hint: 1,.5
on_press: Factory.Dex().open()
MDRaisedButton:
text: "Remi"
font_size: 32
size_hint: 1,.5
on_press: Factory.Remi().open()
MDRectangleFlatIconButton:
id: bt_information
text: "Info"
#text: root.bt_information
#text: p.root.ids.bt_information
icon: "youtube-studio"
font_size: 32
size_hint: 1,.2
text_size: self.size
md_bg_color: 0.95,0.61,0.73,1
on_press: Factory.Info().open()
'''
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|