Yes, but only in specific cases.
First, you can use your bonus action to cast a spell and your action to take the attack action. Only a handful of spells have a casting time of a bonus action, though a sorcerer can use the Quicken Spell metamagic to reduce a spell's casting time to 1 bonus action, at the cost of sorcery points.
Second, A Valor Bard can cast a spell with a casting time of one action and use their bonus action to attack--their level 14 class feature states (PHB 55):
At 14th level, you have mastered the art of weaving spellcasting and weapon use into a single harmonious act. When you use your action to cast a bard spell, you can make one weapon attack as a bonus action.
Third, a 2nd level fighter is able to use action surges, which gives you an extra action (that you can use to cast a spell or attack)
Finally, an Eldritch Knight can cast a spell and make a single attack in a round at various levels:
Beginning at 7th level, when you use your action to cast a cantrip, you can make one weapon attack as a bonus action.
Starting at 18th level, when you use your action to cast a spell, you can make one weapon attack as a bonus action.
Allowing this more generally might make you overpowered.
D&D 5e's action economy and balance revolves around managing a character's action and bonus action. The DMG warns: (DMG 263)
Rules and game elements that override the rules for concentration, reactions, bonus actions, and magic item attunement can seriously unbalance or overcomplicate your game.
Allowing a character to effectively have a second action almost doubles that character's power. The features described above either have pretty tight restrictions that reduce the potential damage output or very high level requirements. If you or your DM want to homebrew a similar feature, you should take some care to balance it.
If you want to think about it in in-game terms, consider that casting a spell requires focus (concentration, one might say), skill, and effort to cast. Attacking with a second weapon might be an extra swipe or two with your off-hand, but committing to a spell is a much bigger deal and takes much longer. A single turn is only 6 seconds, after all!